Merge branch 'master' of https://github.com/michaelklishin/monger
This commit is contained in:
commit
e6f81e52a7
4 changed files with 26 additions and 9 deletions
|
|
@ -4,7 +4,7 @@
|
||||||
:dependencies [[org.clojure/clojure "1.3.0"]
|
:dependencies [[org.clojure/clojure "1.3.0"]
|
||||||
[org.mongodb/mongo-java-driver "2.7.2"]
|
[org.mongodb/mongo-java-driver "2.7.2"]
|
||||||
[com.novemberain/validateur "1.0.0-SNAPSHOT"]]
|
[com.novemberain/validateur "1.0.0-SNAPSHOT"]]
|
||||||
:dev-dependencies [[org.clojure/data.json "0.1.2"]
|
:dev-dependencies [[org.clojure/data.json "0.1.2" :exclusions [org.clojure/clojure]]
|
||||||
[clj-time "0.3.2-SNAPSHOT" :exclusions [org.clojure/clojure]]]
|
[clj-time "0.3.3" :exclusions [org.clojure/clojure]]]
|
||||||
:dev-resources-path "test/resources"
|
:dev-resources-path "test/resources"
|
||||||
:warn-on-reflection true)
|
:warn-on-reflection true)
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@
|
||||||
;;
|
;;
|
||||||
;; monger.collection/count
|
;; monger.collection/count
|
||||||
;;
|
;;
|
||||||
(defn ^long count
|
(defn count
|
||||||
"Returns the number of documents in this collection.
|
"Returns the number of documents in this collection.
|
||||||
|
|
||||||
Takes optional conditions as an argument.
|
Takes optional conditions as an argument.
|
||||||
|
|
@ -150,12 +150,18 @@
|
||||||
(monger.collection/count collection)
|
(monger.collection/count collection)
|
||||||
|
|
||||||
(monger.collection/count collection { :first_name \"Paul\" })"
|
(monger.collection/count collection { :first_name \"Paul\" })"
|
||||||
|
(^long [^String collection]
|
||||||
|
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)]
|
||||||
|
(.count coll)))
|
||||||
|
(^long [^String collection, ^Map conditions]
|
||||||
|
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)]
|
||||||
|
(.count coll (to-db-object conditions)))))
|
||||||
|
|
||||||
|
(defn any?
|
||||||
([^String collection]
|
([^String collection]
|
||||||
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)]
|
(> (count collection) 0))
|
||||||
(.count coll)))
|
|
||||||
([^String collection, ^Map conditions]
|
([^String collection, ^Map conditions]
|
||||||
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)]
|
(> (count collection conditions) 0)))
|
||||||
(.count coll (to-db-object conditions)))))
|
|
||||||
|
|
||||||
|
|
||||||
;; monger.collection/update
|
;; monger.collection/update
|
||||||
|
|
|
||||||
|
|
@ -41,4 +41,4 @@
|
||||||
IPersistentMap
|
IPersistentMap
|
||||||
(get-id
|
(get-id
|
||||||
[^IPersistentMap object]
|
[^IPersistentMap object]
|
||||||
(or (:_id object) ("_id" object))))
|
(or (:_id object) (object "_id"))))
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,13 @@
|
||||||
(mgcol/insert "people" doc)
|
(mgcol/insert "people" doc)
|
||||||
(is (not (nil? (monger.util/get-id doc))))))
|
(is (not (nil? (monger.util/get-id doc))))))
|
||||||
|
|
||||||
|
(deftest insert-a-map-with-id-and-with-default-write-concern
|
||||||
|
(let [collection "people"
|
||||||
|
id (ObjectId.)
|
||||||
|
doc { :name "Joe", :age 30 "_id" id }
|
||||||
|
result (mgcol/insert "people" doc)]
|
||||||
|
(is (= id (monger.util/get-id doc)))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
@ -79,9 +86,13 @@
|
||||||
{ :language "Clojure", :name "incanter" }
|
{ :language "Clojure", :name "incanter" }
|
||||||
{ :language "Scala", :name "akka" }] )
|
{ :language "Scala", :name "akka" }] )
|
||||||
(is (= 4 (mgcol/count collection)))
|
(is (= 4 (mgcol/count collection)))
|
||||||
|
(is (mgcol/any? collection))
|
||||||
(is (= 3 (mgcol/count collection { :language "Clojure" })))
|
(is (= 3 (mgcol/count collection { :language "Clojure" })))
|
||||||
|
(is (mgcol/any? collection { :language "Clojure" }))
|
||||||
(is (= 1 (mgcol/count collection { :language "Scala" })))
|
(is (= 1 (mgcol/count collection { :language "Scala" })))
|
||||||
(is (= 0 (mgcol/count collection { :language "Python" })))))
|
(is (mgcol/any? collection { :language "Scala" }))
|
||||||
|
(is (= 0 (mgcol/count collection { :language "Python" })))
|
||||||
|
(is (not (mgcol/any? collection { :language "Python" })))))
|
||||||
|
|
||||||
|
|
||||||
(deftest remove-all-documents-from-collection
|
(deftest remove-all-documents-from-collection
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue