Support partial documents for monger.collection/find

This commit is contained in:
Michael S. Klishin 2011-08-15 00:22:12 +04:00
parent 228a1b256c
commit f8686896f5

View file

@ -44,6 +44,12 @@
([^String collection, ^Map ref] ([^String collection, ^Map ref]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)]
(.find coll (to-db-object ref)))) (.find coll (to-db-object ref))))
([^String collection, ^Map ref, ^List fields]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)
n (count fields)
ones (replicate n 1)
map-of-fields (zipmap fields ones)]
(.find coll (to-db-object ref) (to-db-object map-of-fields))))
) )
@ -54,7 +60,7 @@
([^String collection, ^String id, ^List fields] ([^String collection, ^String id, ^List fields]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection) (let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)
n (count fields) n (count fields)
ones (replicate 10 1) ones (replicate n 1)
map-of-fields (zipmap fields ones)] map-of-fields (zipmap fields ones)]
(.findOne coll (to-db-object { :_id id }) (to-db-object map-of-fields)))) (.findOne coll (to-db-object { :_id id }) (to-db-object map-of-fields))))
) )