find-one-as-map accepts fields as 3rd parameter
partial resolution of: https://github.com/michaelklishin/monger/issues/8
This commit is contained in:
parent
698cb832e1
commit
31aff189d3
2 changed files with 29 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue