user collections에 data가 아래와 같을 때:
{name:"kim", food:["rice","water" ]}
{name:"lee", food:["rice","orange" ]}
Field Display : _id는 default.
> db.user.find( {name:"kim"}, {food:false, _id:false } )
result: {"name":"kim"}
array
> db.user.find( {food:"rice"} ) : array 1depth까지 바로 탐색.
result: all user 2 line.
update array { $push (rightmost), $pop:1(rightmost), $pull (remove), $addToSet(work like set)
> db.user.update( {name:"kim", {food: { $pop:1}} )
$or,
> db.user.find( { $or:[ { name:"kim"}, {name:"lee"} ] } )
$and
and는 보통 필요가 없다.
> db.user.find( {name:"kim", food:"rice"} ) ?
result: kim user 1 line.
$regex,
> db.user.find( {name: {$regex:" ^k"} } )
result: kim user 1 line.
$exists (=field exists )
> db.user.find( {name: {$exists:true} } )
result: all user 2line
$all,
> db.user.find ( {rice: {$all ["rice","water] }} )
result: kim user 1 line.
$in, (sql 의 in과 유사)
> db.user.find ( {rice: {$in ["orange","water] }} )
result: all user 2 line.