diff --git a/src/monger/operators.clj b/src/monger/operators.clj index b25f3b8..b260ce4 100644 --- a/src/monger/operators.clj +++ b/src/monger/operators.clj @@ -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: diff --git a/test/monger/test/query_operators.clj b/test/monger/test/query_operators.clj index d7c436a..f2e092f 100644 --- a/test/monger/test/query_operators.clj +++ b/test/monger/test/query_operators.clj @@ -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 } }))) \ No newline at end of file + 1 { "comments.rating" { $gt 3 } })))