Adding missing $nin operator.

This commit is contained in:
Oleksandr Petrov 2012-01-25 21:56:06 +01:00
parent 1a8eb1ef80
commit 7ab8d51a84
2 changed files with 12 additions and 4 deletions

View file

@ -37,6 +37,13 @@
;; (mgcol/find-maps "languages" { :tags { $in [ "functional" "object-oriented" ] } } )
(defoperator $in)
;; The $nin operator is similar to $in, but it selects objects for which the specified field does not
;; have any value in the specified array.
;;
;; EXAMPLES
;; (mgcol/find-maps "languages" { :tags { $nin [ "functional" ] } } )
(defoperator $nin)
;; $ne is "non-equals" comparator
;;
;; EXAMPLES:

View file

@ -1,6 +1,6 @@
(set! *warn-on-reflection* true)
(ns monger.test.collection
(ns monger.test.query-operators
(:import [com.mongodb WriteResult WriteConcern DBCursor DBObject CommandResult$CommandFailure MapReduceOutput MapReduceCommand MapReduceCommand$OutputType]
[org.bson.types ObjectId]
[java.util Date])
@ -68,7 +68,7 @@
{:users { $gt 10 } } ]}))))))
;;
;; $all, $in
;; $all, $in, $nin
;;
(deftest find-on-embedded-arrays
@ -78,7 +78,8 @@
{ :language "Ruby", :tags [ "object-oriented" "dynamic" ] }])
(is (= "Scala" (:language (first (mgcol/find-maps collection { :tags { $all [ "functional" "object-oriented" ] } } )))))
(is (= 3 (.count (mgcol/find-maps collection { :tags { $in [ "functional" "object-oriented" ] } } ))))))
(is (= 3 (.count (mgcol/find-maps collection { :tags { $in [ "functional" "object-oriented" ] } } ))))
(is (= 1 (.count (mgcol/find-maps collection { :tags { $nin [ "functional" ] } } ))))))
(deftest find-with-conditional-operators-on-embedded-documents
@ -93,4 +94,4 @@
(are [a b] (= a (.count (mgcol/find collection b)))
1 { :comments { $elemMatch { :text "Nice!" :rating { $gte 1 } } } }
2 { "comments.rating" 1 }
1 { "comments.rating" { $gt 3 } })))
1 { "comments.rating" { $gt 3 } })))