Add affected-count function for WriteResult
This commit is contained in:
parent
c1acd78060
commit
99a113e220
2 changed files with 11 additions and 3 deletions
|
|
@ -65,3 +65,8 @@
|
||||||
(acknowledged?
|
(acknowledged?
|
||||||
[^CommandResult result]
|
[^CommandResult result]
|
||||||
(.ok result)))
|
(.ok result)))
|
||||||
|
|
||||||
|
(defn affected-count
|
||||||
|
"Get the number of documents affected"
|
||||||
|
[^WriteResult result]
|
||||||
|
(.getN result))
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,11 @@
|
||||||
date (Date.)
|
date (Date.)
|
||||||
doc { :created-at date :data-store "MongoDB" :language "Clojure" :_id doc-id }
|
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 }]
|
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}))))
|
(let [result (mc/update db collection { :language "Clojure" } doc {:upsert true})]
|
||||||
(is (mgres/updated-existing? (mc/update db collection { :language "Clojure" } doc {:upsert true})))
|
(is (not (mgres/updated-existing? result)))
|
||||||
(mgres/updated-existing? (mc/update db collection { :language "Clojure" } modified-doc {:multi false :upsert true}))
|
(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)
|
(mc/remove db collection)
|
||||||
(mg/disconnect conn))))
|
(mg/disconnect conn))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue