Data type and Conventions

|
1. MongoDB (BSON) Data types
   string, integer, boolean, double, null, array, object, date, object id, binary data, regular expression, code
   string은 utf8로 저장된다 
   data type체크하기
   x.d instanceof Date
   x.b instanceof BinData
   x.n instanceof NumberLong
   type of x.n2 

   data type : 64 bit values, 앞에 32bit는 second since the UTC epoch, 뒤에 32bit는 현재 초에서의 증가하는 숫자 
                   document에서 _id다음에 column으로 와야지만 실제적인 date type으로 저장된다
                   (순서상 첫번째여야함 _id는 무조건 첫 column데이터이므로)

                   new Timestamp()   -> {"t" : 1293765885000, "i" : 1}
 Object IDS : 모든 document는 unique한 key인 object_id를 갖는다
(_id, 첫번째 attribute로 갖음. capped collection은 기본으로는 존재하지 않음)
user가 array를 제외한 어떤 데이터형으로도 _id를 초기화시킬수 있다  12bytes binary value  ObjectId("47cc67093475061e3d95369d") : string으로 부터 ObjectId를 만들어낸다 

  12-byte로 이루어져있고 4byte는 timestamp, 3byte는 machine id, 2byte는 processid, 3byte는 counter
                        object_id로 사용자는 document 생성시간. seq_id를 얻을 수 있다 (timestamp, counter를 통해서) 
                        id는 무조건 indexing 되어있다.
                        _id 의 value를 셋팅할때는 string으로 넣기보다는 BinData로 넣는게 사이즈를 줄일 수 있다.

2. Database Reference : 명시적으로 collection간의 join을 지원하지 않으므로 join과 비슷한 동작을 하기 위해서
   - Simple Manual Reference : client단에서 직접 document별로 join
      p = db.컬렉션명.findOne();
      a = db.컬렉션명.find({_id:p.person});
   - DBRef 
      DBRef는 collectionname과 object_id를 갖는다 
      만약에 reference하는 collection이 변하지 않는다면 manual reference가 좀 더 효율적이다 
      stu = { name : 'joe', classes : [ new DBRef('courses', x._id) ] }
      stu.classes[0].fetch() 
And