Introduce monger.collection/find-seq
For cases when you do not want to work with DBCursors but also do not need conversion to maps that monger.collection/find-maps does.
This commit is contained in:
parent
db6721ddab
commit
886a270bf9
2 changed files with 46 additions and 25 deletions
|
|
@ -63,6 +63,14 @@
|
|||
([^String collection, ^Map ref, ^List fields]
|
||||
(map (fn [x] (from-db-object x true)) (seq (find collection ref fields)))))
|
||||
|
||||
(defn ^ISeq find-seq
|
||||
([^String collection]
|
||||
(seq (find collection)))
|
||||
([^String collection, ^Map ref]
|
||||
(seq (find collection ref)))
|
||||
([^String collection, ^Map ref, ^List fields]
|
||||
(seq (find collection ref fields))))
|
||||
|
||||
;;
|
||||
;; monger.collection/find-one
|
||||
;;
|
||||
|
|
|
|||
|
|
@ -135,6 +135,10 @@
|
|||
cursor (mgcol/find collection)]
|
||||
(is (empty? (iterator-seq cursor)))))
|
||||
|
||||
(deftest find-document-seq-when-collection-is-empty
|
||||
(let [collection "docs"]
|
||||
(is (empty? (mgcol/find-seq collection)))))
|
||||
|
||||
|
||||
;;
|
||||
;; find-one
|
||||
|
|
@ -278,7 +282,7 @@
|
|||
(is (= 3 (.count (mgcol/find collection { :language "Clojure" }))))
|
||||
(is (empty? (mgcol/find collection { :language "Java" })))))
|
||||
|
||||
(deftest find-and-iterate-over-multiple-documents
|
||||
(deftest find-and-iterate-over-multiple-documents-the-hard-way
|
||||
(let [collection "libraries"]
|
||||
(mgcol/insert-batch collection [{ :language "Clojure", :name "monger" }
|
||||
{ :language "Clojure", :name "langohr" }
|
||||
|
|
@ -286,7 +290,16 @@
|
|||
{ :language "Scala", :name "akka" }])
|
||||
(doseq [doc (take 3 (map (fn [dbo]
|
||||
(monger.conversion/from-db-object dbo true))
|
||||
(iterator-seq (mgcol/find collection { :language "Clojure" }))))]
|
||||
(mgcol/find-seq collection { :language "Clojure" })))]
|
||||
(is (= "Clojure" (:language doc))))))
|
||||
|
||||
(deftest find-and-iterate-over-multiple-documents
|
||||
(let [collection "libraries"]
|
||||
(mgcol/insert-batch collection [{ :language "Clojure", :name "monger" }
|
||||
{ :language "Clojure", :name "langohr" }
|
||||
{ :language "Clojure", :name "incanter" }
|
||||
{ :language "Scala", :name "akka" }])
|
||||
(doseq [doc (take 3 (mgcol/find-maps collection { :language "Clojure" }))]
|
||||
(is (= "Clojure" (:language doc))))))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue