http://www.tutorialspoint.com/mongodb/index.htm


MongoDB - Overview


MongoDB는 cross-platform의 document oriented DB이다. 높은 수준의 성능과 가용성, 쉬운 확장성을 제공하며 Collection과 Document의 개념 내에서 동작한다.

(참고 : Document-Oriented DB가 뭥미? http://lambdaexp.tistory.com/38, ORM(Objected Relational Mapping)을 왜 쓸까? http://www.tutorialspoint.com/mongodb/mongodb_overview.htm)


Database

 Database는 collection을 위한 물리적 그릇이라고 볼 수 있다. 각각의 database는, 각각의 파일 시스템을 갖춘 파일들의 셋을 가지고 있다. 하나의 MongoDB 서버는 일반적으로 여러 개의 데이터베이스를 가진다.


Collection

 Collection은 MongoDB document의 집합체이다. RDBMS table과 같으며 collection은 하나의 데이터베이스 내에 존재한다. Collection은 꼭 일정한 틀을 갖출 필요가 없으며 한 collection내의 document들은 서로 다른 filed를 가질 수도 있다. 일반적으로 하나의 collection내의 모든 document들은 비슷하거나 연관이 있는 목적으로 만들어져 있다.


Document

 document는 key-value pair의 집합이다. document는 dynamic schema를 가지고 있다. Dynamic schema가 뜻하는 것은 같은 Collection 내의 document들이 꼭 같은 field들 혹은 구조를 가질 필요가 없다는 것과, 하나의 collection의 document들의 공통된 field가 서로 다른 data 타입의 값을 가지고 있을 수 있다는 것이다.


아래는 RDBMS 용어와 MongoDB와의 관계를 보여주는 표이다.

RDBMSMongoDB
DatabaseDatabase
TableCollection
Tuple/RowDocument
columnField
Table JoinEmbedded Documents
Primary KeyPrimary Key (Default key _id provided by mongodb itself)
Database Server and Client
Mysqld/Oraclemongod
mysql/sqlplusmongo

document 예제

 아래의 예제는 한 블로그 사이트의 document 구조를 나타내고 있다. 간단하게 콤마로 key-value pair를 구분하였다.


 _id: ObjectId(7df78ad8902c)
   title: 'MongoDB Overview', 
   description: 'MongoDB is no sql database',
   by: 'tutorials point',
   url: 'http://www.tutorialspoint.com',
   tags: ['mongodb', 'database', 'NoSQL'],
   likes: 100, 
   comments: [	
      {
         user:'user1',
         message: 'My first comment',
         dateCreated: new Date(2011,1,20,2,15),
         like: 0 
      },
      {
         user:'user2',
         message: 'My second comments',
         dateCreated: new Date(2011,1,25,7,45),
         like: 5
      }
   ]
}


_id 는 12 바이트의 16진수의 수이다. 이는 각각의 document의 유일성을 결정한다. _id 값은 직접 값 설정을 해 줄 수 있다. 만약 설정을 하지 않았다면 MongoDB 자체에서 매 document마다 생성을 해준다. 이 때 이 12 바이트는 현재 timestamp의 첫 4 바이트와 machine id 3 바이트, mongodb server의 pid의 2 바이트로 이루어 져 있으며 나머지 3 바이트는 단순한 증가값으로 채워진다.

Posted by Righ
,