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" ] } } ) ;; (mgcol/find-maps "languages" { :tags { $in [ "functional" "object-oriented" ] } } )
(defoperator $in) (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 ;; $ne is "non-equals" comparator
;; ;;
;; EXAMPLES: ;; EXAMPLES:

View file

@ -1,6 +1,6 @@
(set! *warn-on-reflection* true) (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] (:import [com.mongodb WriteResult WriteConcern DBCursor DBObject CommandResult$CommandFailure MapReduceOutput MapReduceCommand MapReduceCommand$OutputType]
[org.bson.types ObjectId] [org.bson.types ObjectId]
[java.util Date]) [java.util Date])
@ -68,7 +68,7 @@
{:users { $gt 10 } } ]})))))) {:users { $gt 10 } } ]}))))))
;; ;;
;; $all, $in ;; $all, $in, $nin
;; ;;
(deftest find-on-embedded-arrays (deftest find-on-embedded-arrays
@ -78,7 +78,8 @@
{ :language "Ruby", :tags [ "object-oriented" "dynamic" ] }]) { :language "Ruby", :tags [ "object-oriented" "dynamic" ] }])
(is (= "Scala" (:language (first (mgcol/find-maps collection { :tags { $all [ "functional" "object-oriented" ] } } ))))) (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 (deftest find-with-conditional-operators-on-embedded-documents