user collections에 data가 아래와 같을 때:

  {name:"kim", phone:{mobile:"010-1234", office:"02-1234" }}

  {name:"lee",  phone:{mobie:"010-2222", office:"02-2222" }}

 

Sub Document

>  db.user.find(  {phone:{mobile:"010-1234", office:"02-1234"}  } )       : mobile, office 순서가 일치해야지만 찾음. Exact match

 

result:  kim user 1 line.

>  db.user.find(  {phone:{mobile:"010-1234" }}) 

result: no result

 

Cursor

>  

cur=db.user.find();null;  (null 이 잠시대기함)> while (cur.hasNext()) printjson(cur.next());

result: all 2users. 2 line
 
 ( Doc 조회 이전 or empty일 때,  설정 가능한 작업들)
> cur.sort( {name:-1}  );null;                       //  reverse order -> return new Cursor. so need null;

> cur.sort( {name:-1}  ).limit(3); ;null;     // limit 3. -> return new Cursor. so need null;

 

update

대표예제:  db.b2bRawCncity.updateMany({cmId:{$gt:240400007}}, {$set:{cmId:null}} );

 

>  db.user.update(  {name:"kim"},   { name:"kim2"} )     //문서 전체 udpate. 

result:  kim->kim2  phone은 날아감. (disappear)

  $set

  >  db.user.update(  {name:"kim"},   { $set: { name:"kim2"} )  //just update

 result:  kim->kim2  phone remain.

  $unset

  >  db.user.update(  {name:"kim"},   { $unset: { phone:1} )

  field  phone remove

  $upsert : true   means  => 없을 때 insert 하라는 의미.

  $multi : true   means  => 여러건 update 할 때  필수. default는 한 건만 update.

 

$type:2    string을 의미함. bson의 저장방식으로 숫자마다 다른 type을 의미함.

 

 

Posted by yongary
,