From ad2ee531a3e0192601d3c12b9eeea4aeab5ccf22 Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Sun, 2 Dec 2018 21:23:20 +0300 Subject: [PATCH] $pushAll is gone, replaced by $push + $each See https://docs.mongodb.com/v3.2/reference/operator/update/each/#up._S_each. --- src/clojure/monger/operators.clj | 8 -------- test/monger/test/atomic_modifiers_test.clj | 16 ++++++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/clojure/monger/operators.clj b/src/clojure/monger/operators.clj index 6cb469c..0b4a6a8 100644 --- a/src/clojure/monger/operators.clj +++ b/src/clojure/monger/operators.clj @@ -196,14 +196,6 @@ ;; (mgcol/update coll { :_id oid } { $push { :tags { $each ["mongodb" "docs"] } } }) (defoperator $each) -;; $pushAll appends each value in value_array to field, if field is an existing array, otherwise sets field to the array value_array -;; if field is not present. If field is present but is not an array, an error condition is raised. -;; Deprecated since MongoDB 2.4, $push with $each modifier should be used instead. -;; -;; EXAMPLES: -;; (mgcol/update coll { :_id oid } { $pushAll { :tags ["mongodb" "docs"] } }) -(defoperator $pushAll) - ;; $addToSet Adds value to the array only if its not in the array already, if field is an existing array, otherwise sets field to the ;; array value if field is not present. If field is present but is not an array, an error condition is raised. ;; diff --git a/test/monger/test/atomic_modifiers_test.clj b/test/monger/test/atomic_modifiers_test.clj index 0eb6fbb..23cdacb 100644 --- a/test/monger/test/atomic_modifiers_test.clj +++ b/test/monger/test/atomic_modifiers_test.clj @@ -174,7 +174,7 @@ ;; this is a common mistake, I leave it here to demonstrate it. You almost never - ;; actually want to do this! What you really want is to use $pushAll instead of $push. MK. + ;; actually want to do this! What you really want is to use $push with $each instead of $push. MK. (deftest add-array-value-to-an-existing-array-using-$push-modifier (let [coll "docs" oid (ObjectId.) @@ -228,34 +228,34 @@ (mc/find-map-by-id db coll oid))))) ;; - ;; $pushAll + ;; $push + $each (formerly $pushAll) ;; - (deftest initialize-an-array-using-$pushAll-modifier + (deftest initialize-an-array-using-$push-and-$each-modifiers (let [coll "docs" oid (ObjectId.) title "$pushAll modifier appends multiple values to field"] (mc/insert db coll {:_id oid :title title}) - (mc/update db coll {:_id oid} {$pushAll {:tags ["mongodb" "docs"]}}) + (mc/update db coll {:_id oid} {$push {:tags {$each ["mongodb" "docs"]}}}) (is (= {:_id oid :title title :tags ["mongodb" "docs"]} (mc/find-map-by-id db coll oid))))) - (deftest add-value-to-an-existing-array-using-$pushAll-modifier + (deftest add-value-to-an-existing-array-using-$push-and-$each-modifier (let [coll "docs" oid (ObjectId.) title "$pushAll modifier appends multiple values to field"] (mc/insert db coll {:_id oid :title title :tags ["mongodb"]}) - (mc/update db coll {:_id oid} {$pushAll {:tags ["modifiers" "docs"]}}) + (mc/update db coll {:_id oid} {$push {:tags {$each ["modifiers" "docs"]}}}) (is (= {:_id oid :title title :tags ["mongodb" "modifiers" "docs"]} (mc/find-map-by-id db coll oid))))) - (deftest double-add-value-to-an-existing-array-using-$pushAll-modifier + (deftest double-add-value-to-an-existing-array-using-$push-and-$each-modifier (let [coll "docs" oid (ObjectId.) title "$pushAll modifier appends multiple values to field"] (mc/insert db coll {:_id oid :title title :tags ["mongodb" "docs"]}) - (mc/update db coll {:_id oid} {$pushAll {:tags ["modifiers" "docs"]}}) + (mc/update db coll {:_id oid} {$push {:tags {$each ["modifiers" "docs"]}}}) (is (= {:_id oid :title title :tags ["mongodb" "docs" "modifiers" "docs"]} (mc/find-map-by-id db coll oid)))))