This commit is contained in:
GitHub Merge Button 2012-02-18 03:03:13 -08:00
commit d87bb8d060
3 changed files with 13 additions and 9 deletions

View file

@ -168,7 +168,7 @@
"Returns a single object converted to Map from this collection matching the query." "Returns a single object converted to Map from this collection matching the query."
([^String collection ^Map ref] ([^String collection ^Map ref]
(from-db-object ^DBObject (find-one collection ref) true)) (from-db-object ^DBObject (find-one collection ref) true))
([^String collection ^Map ref fields] ([^String collection ^Map ref ^List fields]
(from-db-object ^DBObject (find-one collection ref fields) true)) (from-db-object ^DBObject (find-one collection ref fields) true))
([^String collection ^Map ref ^List fields keywordize] ([^String collection ^Map ref ^List fields keywordize]
(from-db-object ^DBObject (find-one collection ref fields) keywordize))) (from-db-object ^DBObject (find-one collection ref fields) keywordize)))
@ -205,9 +205,9 @@
([^String collection id] ([^String collection id]
(check-not-nil! id "id must not be nil") (check-not-nil! id "id must not be nil")
(from-db-object ^DBObject (find-one-as-map collection { :_id id }) true)) (from-db-object ^DBObject (find-one-as-map collection { :_id id }) true))
([^String collection id keywordize] ([^String collection id ^List fields]
(check-not-nil! id "id must not be nil") (check-not-nil! id "id must not be nil")
(from-db-object ^DBObject (find-one-as-map collection { :_id id }) keywordize)) (from-db-object ^DBObject (find-one-as-map collection { :_id id } fields) true))
([^String collection id ^List fields keywordize] ([^String collection id ^List fields keywordize]
(check-not-nil! id "id must not be nil") (check-not-nil! id "id must not be nil")
(from-db-object ^DBObject (find-one-as-map collection { :_id id } fields) keywordize))) (from-db-object ^DBObject (find-one-as-map collection { :_id id } fields) keywordize)))

View file

@ -74,7 +74,7 @@
oid (ObjectId.)] oid (ObjectId.)]
(mgcol/insert coll { :_id oid :weight 10.0 :height 15.2 }) (mgcol/insert coll { :_id oid :weight 10.0 :height 15.2 })
(mgcol/update coll { :_id oid } { $set { :weight 20.5 :height 25.6 } }) (mgcol/update coll { :_id oid } { $set { :weight 20.5 :height 25.6 } })
(is (= { :_id oid :weight 20.5 :height 25.6 } (mgcol/find-map-by-id coll oid [:weight]))))) (is (= { :_id oid :weight 20.5 :height 25.6 } (mgcol/find-map-by-id coll oid [:weight :height])))))
(deftest update-and-set-multiple-fields-using-$set-modifier (deftest update-and-set-multiple-fields-using-$set-modifier
@ -82,7 +82,7 @@
oid (ObjectId.)] oid (ObjectId.)]
(mgcol/insert coll { :_id oid :weight 10.0 }) (mgcol/insert coll { :_id oid :weight 10.0 })
(mgcol/update coll { :_id oid } {$set { :weight 20.5 :height 25.6 } }) (mgcol/update coll { :_id oid } {$set { :weight 20.5 :height 25.6 } })
(is (= { :_id oid :weight 20.5 :height 25.6 } (mgcol/find-map-by-id coll oid [:weight]))))) (is (= { :_id oid :weight 20.5 :height 25.6 } (mgcol/find-map-by-id coll oid [:weight :height])))))
;; ;;

View file

@ -162,9 +162,13 @@
(deftest find-partial-document-as-map-by-id-when-document-does-exist (deftest find-partial-document-as-map-by-id-when-document-does-exist
(let [collection "libraries" (let [collection "libraries"
doc-id (monger.util/random-uuid) doc-id (monger.util/random-uuid)
doc { :data-store "MongoDB", :language "Clojure", :_id doc-id }] fields [:data-store]
(mgcol/insert collection doc) doc { :data-store "MongoDB", :language "Clojure", :_id doc-id }
(is (= ({ :language "Clojure" } (mgcol/find-map-by-id collection doc-id [ :language ])))))) _ (mgcol/insert collection doc)
loaded (mgcol/find-map-by-id collection doc-id [ :language ])]
(is (= { :language "Clojure", :_id doc-id } loaded ))
)
)
;; ;;