[mongodb] mongodb 검색하기
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/