Inserting

|
1. indexing관련
    indexing을 많이 할 수록 write가 느려지지만 read는 빨라 질 수 있다. 

2. collection 갯수과 관련
    mongodb는 collection data를 countinuous하게 disk에 쓰기때문에 하나의 collectoin에 모든 데이터를 넣었을 경우에는  
   성능상의 이슈가 생길 수 있다
And

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

collection관련

|
collection관련 명령어
처음 use mall 하면 mall이라는 database로 가는 것이고 이 곳에서 db.product.save() 하는 순간부터
product가 mall이라는 database의 하위 collection이 되는것임 (use mall 이 된 상태이기 때문에 이미 database는 mall인 상태임)
show collections : 현재 name space내의 collection이름
db.컬렉션명.find().sort({name : 1, age : -1}) : name 오름차순 age 내림차순으로 정렬
db.capped컬렉션명.find().sort({$natural : -1}).limit(50) : 최신순 정렬 (기본 cappedCollection은 insert순이다)

1. 일반적인 collection
   rdbms에서의table과 같은의미

2. capped collection
   FIFO기능을 갖고 있는 고성능의 테이블
   기본적인 natural order는 insert order
   용량제한이 있다. collection이 꽉차면 가장 처음에 들어간 데이터 순으로 삭제된다. 
   db.createCollection("컬렉션이름", {capped:true, size:100000})
   사용될 수 있는 application : logging,  caching, auto archiving
   db.runCommand( {createCollection:"컬렉션명", capped : true, size : 100000})
   show collections 현재 namespace상의 collections을 보여준다
 
And
prev | 1 | ··· | 5 | 6 | 7 | 8 | 9 | 10 | 11 | ··· | 21 | next