diff --git a/src/monger/collection.clj b/src/monger/collection.clj index ad63627..fbbecb3 100644 --- a/src/monger/collection.clj +++ b/src/monger/collection.clj @@ -8,7 +8,7 @@ ;; You must not remove this notice, or any other, from this software. (ns monger.collection - (:refer-clojure :exclude [find remove count]) + (:refer-clojure :exclude [find remove count drop]) (:import (com.mongodb Mongo DB DBCollection WriteResult DBObject WriteConcern DBCursor) (java.util List Map) (clojure.lang IPersistentMap ISeq)) (:require [monger core result]) (:use [monger.convertion])) @@ -174,11 +174,11 @@ (defn ensure-index ([^String collection, ^Map keys] - (let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] - (.ensureIndex coll (to-db-object keys)))) + (let [coll ^DBCollection (.getCollection monger.core/*mongodb-database* collection)] + (.ensureIndex ^DBCollection coll ^DBObject (to-db-object keys)))) ([^String collection, ^Map keys, ^String name] - (let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] - (.ensureIndex coll (to-db-object keys) name)))) + (let [coll ^DBCollection (.getCollection monger.core/*mongodb-database* collection)] + (.ensureIndex coll ^DBObject (to-db-object keys) ^String name)))) ;; @@ -205,6 +205,16 @@ (.dropIndexes ^DBCollection (.getCollection monger.core/*mongodb-database* collection))) +(defn exists? + [^String collection] + (.collectionExists monger.core/*mongodb-database* collection)) + +(defn drop + [^String collection] + (let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] + (.drop coll))) + + ;; ;; Implementation ;; diff --git a/test/monger/test/collection.clj b/test/monger/test/collection.clj index cdbb762..dad1b85 100644 --- a/test/monger/test/collection.clj +++ b/test/monger/test/collection.clj @@ -382,3 +382,19 @@ (:name (second (monger.collection/indexes-on collection))))) (monger.collection/ensure-index collection { "language" 1 }))) + +;; +;; exists?, drop +;; + +(deftest checking-for-collection-existence-when-it-does-not-exist + (let [collection "widgets"] + (monger.collection/drop collection) + (is (false? (monger.collection/exists? collection))))) + +(deftest checking-for-collection-existence-when-it-does-exist + (let [collection "widgets"] + (monger.collection/drop collection) + (monger.collection/insert-batch collection [{ :name "widget1" } + { :name "widget2" }]) + (is (monger.collection/exists? collection)))) \ No newline at end of file