Extend monger.core/count to MapReduceOutput
This commit is contained in:
parent
8f18d30e43
commit
a6d15dbbe1
2 changed files with 9 additions and 5 deletions
|
|
@ -14,7 +14,7 @@
|
|||
monger.core
|
||||
(:refer-clojure :exclude [count])
|
||||
(:use [monger.conversion])
|
||||
(:import [com.mongodb Mongo DB WriteConcern DBObject DBCursor CommandResult Bytes MongoOptions ServerAddress]
|
||||
(:import [com.mongodb Mongo DB WriteConcern DBObject DBCursor CommandResult Bytes MongoOptions ServerAddress MapReduceOutput]
|
||||
[com.mongodb.gridfs GridFS]
|
||||
[java.util Map]))
|
||||
|
||||
|
|
@ -237,7 +237,11 @@
|
|||
(extend-protocol Countable
|
||||
DBCursor
|
||||
(count [^DBCursor this]
|
||||
(.count this)))
|
||||
(.count this))
|
||||
|
||||
MapReduceOutput
|
||||
(count [^MapReduceOutput this]
|
||||
(.count (.results this))))
|
||||
|
||||
(defn ^DBObject get-last-error
|
||||
"Returns the the error (if there is one) from the previous operation on this connection.
|
||||
|
|
|
|||
|
|
@ -61,9 +61,9 @@
|
|||
(is (mgres/ok? (mgcol/insert-batch collection batch)))
|
||||
(mgcol/map-reduce collection mapper reducer "merged_mr_outputs" MapReduceCommand$OutputType/MERGE {})
|
||||
(is (mgres/ok? (mgcol/insert collection { :state "OR" :price 17.95 :quantity 4 })))
|
||||
(let [output (mgcol/map-reduce collection mapper reducer "merged_mr_outputs" MapReduceCommand$OutputType/MERGE {})]
|
||||
(let [^MapReduceOutput output (mgcol/map-reduce collection mapper reducer "merged_mr_outputs" MapReduceCommand$OutputType/MERGE {})]
|
||||
(mgres/ok? output)
|
||||
(is (= 4 (monger.core/count (.results ^MapReduceOutput output))))
|
||||
(is (= 4 (monger.core/count output)))
|
||||
(is (= ["CA" "IL" "NY" "OR"]
|
||||
(map :_id (mgcol/find-maps "merged_mr_outputs"))))
|
||||
(.drop ^MapReduceOutput output))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue