Introduce a way to run "raw" commands (using DBObjects)

This commit is contained in:
Michael Klishin 2014-03-02 21:31:26 +04:00
parent 413d4484b8
commit 555ac53d22
2 changed files with 13 additions and 1 deletions

View file

@ -20,7 +20,7 @@
* http://clojuremongodb.info/articles/mapreduce.html" * http://clojuremongodb.info/articles/mapreduce.html"
(:require monger.core (:require monger.core
[monger.conversion :refer :all]) [monger.conversion :refer :all])
(:import com.mongodb.DB)) (:import [com.mongodb DB DBObject]))
;; ;;
@ -32,6 +32,11 @@
[m] [m]
(monger.core/command (monger.core/admin-db) m)) (monger.core/command (monger.core/admin-db) m))
(defn raw-admin-command
"Executes a command on the admin database"
[^DBObject cmd]
(monger.core/raw-command (monger.core/admin-db) cmd))
(defn collection-stats (defn collection-stats
([collection] ([collection]
(collection-stats monger.core/*mongodb-database* collection)) (collection-stats monger.core/*mongodb-database* collection))

View file

@ -263,6 +263,13 @@
([^DB database ^Map cmd] ([^DB database ^Map cmd]
(.command ^DB database ^DBObject (to-db-object cmd)))) (.command ^DB database ^DBObject (to-db-object cmd))))
(defn ^com.mongodb.CommandResult raw-command
"Like monger.core/command but accepts DBObjects"
([^DBObject cmd]
(.command ^DB *mongodb-database* cmd))
([^DB database ^DBObject cmd]
(.command database cmd)))
(defprotocol Countable (defprotocol Countable
(count [this] "Returns size of the object")) (count [this] "Returns size of the object"))