diff --git a/src/monger/collection.clj b/src/monger/collection.clj index edb646e..7a6c76e 100644 --- a/src/monger/collection.clj +++ b/src/monger/collection.clj @@ -155,12 +155,18 @@ "Returns a single object converted to Map from this collection matching the query." ([^String collection ^Map ref] (from-db-object ^DBObject (find-one collection ref) true)) - ([^String collection ^Map ref keywordize] - (from-db-object ^DBObject (find-one collection ref) keywordize)) + ([^String collection ^Map ref fields] + (from-db-object ^DBObject (find-one collection ref fields) true)) ([^String collection ^Map ref ^List fields keywordize] (from-db-object ^DBObject (find-one collection ref fields) keywordize))) + ; ([^String collection ^Map ref keywordize] + ; (from-db-object ^DBObject (find-one collection ref fields) keywordize)) + ; ([^String collection ^Map ref ^List fields keywordize] + ; (from-db-object ^DBObject (find-one collection ref fields) keywordize))) + + ;; ;; monger.collection/find-by-id diff --git a/test/monger/test/regular_finders.clj b/test/monger/test/regular_finders.clj index 9c97116..bad3f0a 100644 --- a/test/monger/test/regular_finders.clj +++ b/test/monger/test/regular_finders.clj @@ -68,9 +68,29 @@ doc { :data-store "MongoDB", :language "Clojure", :_id doc-id } fields [:data-store]] (mgcol/insert collection doc) - (is (= { :data-store "MongoDB", :_id doc-id } (mgcol/find-one-as-map collection { :language "Clojure" } fields true))))) + (is (= { :data-store "MongoDB", :_id doc-id } (mgcol/find-one-as-map collection { :language "Clojure" } fields))))) +(deftest find-one-partial-document-as-map-when-collection-has-matches-with-keywordize + (let [collection "docs" + doc-id (monger.util/random-uuid) + doc { :data-store "MongoDB", :language "Clojure", :_id doc-id } + fields [:data-store] + _id (mgcol/insert collection doc) + loaded (mgcol/find-one-as-map collection { :language "Clojure" } fields true) + ] + (is (= { :data-store "MongoDB", :_id doc-id } loaded )))) + + +(deftest find-one-partial-document-as-map-when-collection-has-matches-with-keywordize-false + (let [collection "docs" + doc-id (monger.util/random-uuid) + doc { :data-store "MongoDB", :language "Clojure", :_id doc-id } + fields [:data-store] + _id (mgcol/insert collection doc) + loaded (mgcol/find-one-as-map collection { :language "Clojure" } fields false) + ] + (is (= { "_id" doc-id, "data-store" "MongoDB" } loaded )))) ;; ;; find-by-id