diff --git a/src/clojure/monger/collection.clj b/src/clojure/monger/collection.clj index 9950564..17d15ab 100644 --- a/src/clojure/monger/collection.clj +++ b/src/clojure/monger/collection.clj @@ -97,7 +97,7 @@ ;; and it does not work very well in our case, because that DBObject is short lived and produced ;; from the Clojure map we are passing in. Plus, this approach is very awkward with immutable data ;; structures being the default. MK. - (let [doc (merge document {:_id (ObjectId.)})] + (let [doc (merge {:_id (ObjectId.)} document)] (insert db collection doc concern) doc))) diff --git a/test/monger/test/inserting_test.clj b/test/monger/test/inserting_test.clj index 5f0ad0d..a687180 100644 --- a/test/monger/test/inserting_test.clj +++ b/test/monger/test/inserting_test.clj @@ -129,6 +129,13 @@ (is (:_id result)) (is (= 1 (mc/count collection))))) +(deftest insert-and-return-with-a-provided-id + (let [collection "people" + oid (ObjectId.) + doc {:name "Joe" :age 30 :_id oid} + result (mc/insert-and-return :people doc)] + (is (= (:_id result) (:_id doc) oid)) + (is (= 1 (mc/count collection))))) ;;