findOne(), find()로 간단히 검색할 수 있다.


http://knight76.tistory.com/entry/mongodb-%EA%B2%80%EC%83%89%ED%95%98%EA%B8%B0-find-findOne



Date 타입인 경우, $gte, $lte를 이용하여 시간 검색도 할 수 있다. 


> db.contents.find( {"created_at" : { "$gte":"2014-10-09T13:32:37Z", "$lte":"2014-10-09T13:32:38Z" } } )



미디어 타입이 image나 music인 것을 $in으로 검색할 수 있다.


> db.contents.find( {"media_type" : {"$in" : ["image", "music"]}})



그 반대로 image나 music이 아닌 것을 찾으려면 $nin을 사용한다.


> db.contents.find( {"media_type" : {"$nin" : ["image", "music"]}})



$ne는 not eqaul로서..

$or는 그 중의 하나를..

$not는 아닌 것을 검색할 때 쓰인다.


특정 타입($type) 또는 null 데이터를 검색할 수 있다.


> db.contents.find( { "comments" : null } )



mongodb 2.4부터는 where절을 쓸 수 있다. 부모에서만 쓸 수 있고 자식에서는 쓸 수 없다.

하나 이상의 키 값을 가지고 계산할 때 $where 절을 쓸 수 있다. 


> db.contents.find( { "$where" : "this.xxxx_count + this.aaaa_count >= 5" } )






참고

https://docs.mongodb.org/manual/reference/operator/query-comparison/


https://docs.mongodb.org/manual/reference/operator/query-logical/




'mongodb' 카테고리의 다른 글

mongodb 3.2 특징  (0) 2015.11.10
[mongodb] 커서 (cursor)  (0) 2015.11.09
[mongodb] _id, ObjectId  (0) 2015.11.09
[mongodb] 레플리카 구성 요소  (0) 2015.11.02
[mongodb] master 노드 변경하기  (0) 2015.10.30
Posted by '김용환'
,