mongoDB는 NoSQL(Not only SQL)의 일종으로 document database이다. mongoDB는 데이터 레코드를 BSON 문서로 저장한다. BSON은 JSON의 이진 표현이며, 더 많은 데이터 유형을 포함한다.
NoSQL은 관계형 데이터베이스의 단점을 해결하기 위해 등장했다.
mongoDB document는 field-value 쌍으로 구성되며 아래와 같은 구조를 갖는다
{
field1: value1,
field2: value2,
field3: value3,
...
fieldN: valueN
}
필드 값은 다른 document, 배열 및 document 배열을 포함한 BSON 데이터 유형 중 하나일 수 있다. 예를 들어 아래 document에는 다양한 유형의 값이 포함되어 있다
var mydoc = {
_id: ObjectId("5099803df3f4948bd2f98391"),
name: { first: "Alan", last: "Turing" },
birth: new Date('Jun 23, 1912'),
death: new Date('Jun 07, 1954'),
contribs: [ "Turing machine", "Turing test", "Turingery" ],
views : NumberLong(1250000)
}
_id
: ObjectId 를 보유한다.name
: first
, last
필드를 포함하는 embedded document를 보유한다 .birth
, death
: Date 유형의 값을 보유한다.contribs
*: 문자열 array*를 보유한다.views
: NumberLong 유형의 값을 보유한다.MongoDB 는 dot notation 을 사용해서 배열이나 document 내의 요소에 접근한다.
array
{
...
contribs: [ "Turing machine", "Turing test", "Turingery" ],
...
}
"contribs.2"
embedded document
{
...
name: { first: "Alan", last: "Turing" },
contact: { phone: { type: "cell", number: "111-222-3333" } },
...
}
contact.phone
: { type: "cell", number: "111-222-3333" }
contact.phone.type
: “cell”
JavaScript 개체와 달리 BSON document의 필드는 순서가 지정된다.
document를 비교할 때 필드 순서가 중요하다
a
예를 들어 문서를 필드 와 b
쿼리 에서 비교할 때 :{a: 1, b: 1}
== {a: 1, b: 1}
{a: 1, b: 1}
!= {b: 1, a: 1}
RDBMS | MongoDB (NoSQL) |
---|---|
database | database |
table | collection |
tuple / row | document |
column | key / field |
table join | embedded documents |
primary key | primary key (_id) |
High Performance
mongoDB는 고성능 data persistance를 제공한다 !
Query API
CRUD(읽기 및 쓰기 작업) 와 다음을 지원한다.
High Availability
replica set 이라고 하는 MongoDB의 복제 기능은 다음을 제공한다
Horizontal Scalability
MongoDB는 수평적 확장성을 제공한다 !
Support for Multiple Storage Engine
여러 스토리지 엔진을 제공한다