Merge branch 'issue_8'

This commit is contained in:
Michael S. Klishin 2012-02-12 09:58:48 +04:00
commit b2b0f12aaa
3 changed files with 46 additions and 3 deletions

23
ChangeLog.md Normal file
View file

@ -0,0 +1,23 @@
## Changes between 1.0.0-beta1 and 1.0.0-beta2
### 3-arity of monger.collection/find-one-as-map now takes a vector of fields
3-arity of monger.collection/find-one-as-map now takes a vector of fields
instead of `keywordize` to better fit a more commonly needed case.
``` clojure
;; 3-arity in 1.0.0-beta1
(monger.collection/find-one-as-map "documents" { :first_name "John" } false)
```
``` clojure
;; 3-arity in 1.0.0-beta2
(monger.collection/find-one-as-map "documents" { :first_name "John" } [:first\_name, :last\_name, :age])
```
If you need to use `keywordize`, use 4-arity:
``` clojure
(monger.collection/find-one-as-map "documents" { :first_name "John" } [:first\_name, :last\_name, :age] false)
```

View file

@ -155,8 +155,8 @@
"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 keywordize] ([^String collection ^Map ref fields]
(from-db-object ^DBObject (find-one collection ref) keywordize)) (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)))

View file

@ -68,9 +68,29 @@
doc { :data-store "MongoDB", :language "Clojure", :_id doc-id } doc { :data-store "MongoDB", :language "Clojure", :_id doc-id }
fields [:data-store]] fields [:data-store]]
(mgcol/insert collection doc) (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 ;; find-by-id