From f29d62f1816234f14fbb263201c9c7aaed63a2a3 Mon Sep 17 00:00:00 2001 From: "Michael S. Klishin" Date: Mon, 31 Oct 2011 02:40:55 +0400 Subject: [PATCH] Tests/examples for $pull and $pullAll modifiers --- test/monger/test/atomic_modifiers.clj | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/monger/test/atomic_modifiers.clj b/test/monger/test/atomic_modifiers.clj index c643847..252cb75 100644 --- a/test/monger/test/atomic_modifiers.clj +++ b/test/monger/test/atomic_modifiers.clj @@ -2,7 +2,8 @@ (ns monger.test.atomic-modifiers (:import [com.mongodb WriteResult WriteConcern DBCursor DBObject CommandResult$CommandFailure] - [org.bson.types ObjectId]) + [org.bson.types ObjectId] + [java.util Date]) (:require [monger core util] [monger.collection :as mgcol] [monger.result :as mgres]) @@ -250,3 +251,29 @@ (mgcol/insert coll { :_id oid :title title :tags ["products" "apple" "reviews"] :categories ["apple" "reviews" "drafts"] }) (mgcol/update coll { :_id oid } { "$pop" { :tags 1 :categories 1 } }) (is (= { :_id oid :title title :tags ["products" "apple"] :categories ["apple" "reviews"] } (mgcol/find-map-by-id coll oid))))) + + +;; +;; $pull +;; + +(deftest remove-all-value-entries-from-array-using-$pull-modifier + (let [coll "docs" + oid (ObjectId.) + title "$pull modifier removes all value entries in the array"] + (mgcol/insert coll { :_id oid :title title :measurements [1.0 1.2 1.2 1.2 1.1 1.1 1.2 1.3 1.0] }) + (mgcol/update coll { :_id oid } { "$pull" { :measurements 1.2 } }) + (is (= { :_id oid :title title :measurements [1.0 1.1 1.1 1.3 1.0] } (mgcol/find-map-by-id coll oid))))) + + +;; +;; $pullAll +;; + +(deftest remove-all-value-entries-from-array-using-$pullAll-modifier + (let [coll "docs" + oid (ObjectId.) + title "$pull modifier removes all value entries in the array"] + (mgcol/insert coll { :_id oid :title title :measurements [1.0 1.2 1.2 1.2 1.1 1.1 1.2 1.3 1.0] }) + (mgcol/update coll { :_id oid } { "$pullAll" { :measurements [1.0 1.1 1.2] } }) + (is (= { :_id oid :title title :measurements [1.3] } (mgcol/find-map-by-id coll oid)))))