Merge pull request #153 from eunmin/add-affected-count

Add affected-count function for WriteResult
This commit is contained in:
Michael Klishin 2017-01-11 13:09:46 +08:00 committed by GitHub
commit f3d8a7bb71
2 changed files with 11 additions and 3 deletions

View file

@ -65,3 +65,8 @@
(acknowledged?
[^CommandResult result]
(.ok result)))
(defn affected-count
"Get the number of documents affected"
[^WriteResult result]
(.getN result))

View file

@ -15,8 +15,11 @@
date (Date.)
doc { :created-at date :data-store "MongoDB" :language "Clojure" :_id doc-id }
modified-doc { :created-at date :data-store "MongoDB" :language "Erlang" :_id doc-id }]
(is (not (mgres/updated-existing? (mc/update db collection { :language "Clojure" } doc {:upsert true}))))
(is (mgres/updated-existing? (mc/update db collection { :language "Clojure" } doc {:upsert true})))
(mgres/updated-existing? (mc/update db collection { :language "Clojure" } modified-doc {:multi false :upsert true}))
(let [result (mc/update db collection { :language "Clojure" } doc {:upsert true})]
(is (not (mgres/updated-existing? result)))
(is (= 1 (mgres/affected-count result))))
(is (mgres/updated-existing? (mc/update db collection { :language "Clojure" } doc {:upsert true})))
(is (mgres/updated-existing? (mc/update db collection { :language "Clojure" } modified-doc {:multi false :upsert true})))
(is (= 1 (mgres/affected-count (mc/remove db collection { :_id doc-id }))))
(mc/remove db collection)
(mg/disconnect conn))))