diff --git a/src/monger/collection.clj b/src/monger/collection.clj index 897b11e..8f63ea4 100644 --- a/src/monger/collection.clj +++ b/src/monger/collection.clj @@ -206,7 +206,7 @@ ;; -;; monger.collection/exists?, monger.collection/create, monger.collection/drop +;; monger.collection/exists?, /create, /drop, /rename ;; @@ -223,6 +223,13 @@ (let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (.drop coll))) +(defn rename + ([^String from, ^String to] + (let [^DBCollection coll (.getCollection monger.core/*mongodb-database* from)] + (.rename coll to))) + ([^String from, ^String to, ^Boolean drop-target] + (let [^DBCollection coll (.getCollection monger.core/*mongodb-database* from)] + (.rename coll to drop-target)))) ;; ;; Implementation diff --git a/test/monger/test/collection.clj b/test/monger/test/collection.clj index 88b4d3b..6f8b4ce 100644 --- a/test/monger/test/collection.clj +++ b/test/monger/test/collection.clj @@ -402,5 +402,7 @@ (is (false? (monger.collection/exists? collection))) (monger.collection/create "widgets" { :capped true :max 100 }) (is (monger.collection/exists? collection)) - (monger.collection/drop collection) - )) \ No newline at end of file + (monger.collection/rename collection "gadgets") + (is (not (monger.collection/exists? collection))) + (is (monger.collection/exists? "gadgets")) + (monger.collection/drop "gadgets")))