From 1f091ab735cea309695ace62004e1ed8d0c286a3 Mon Sep 17 00:00:00 2001 From: "Michael S. Klishin" Date: Sat, 10 Sep 2011 08:19:19 +0400 Subject: [PATCH] Implement monger.collection/create --- src/monger/collection.clj | 9 +++++++++ test/monger/test/collection.clj | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/monger/collection.clj b/src/monger/collection.clj index fbbecb3..897b11e 100644 --- a/src/monger/collection.clj +++ b/src/monger/collection.clj @@ -205,10 +205,19 @@ (.dropIndexes ^DBCollection (.getCollection monger.core/*mongodb-database* collection))) +;; +;; monger.collection/exists?, monger.collection/create, monger.collection/drop +;; + + (defn exists? [^String collection] (.collectionExists monger.core/*mongodb-database* collection)) +(defn create + [^String collection, ^Map options] + (.createCollection monger.core/*mongodb-database* collection (to-db-object options))) + (defn drop [^String collection] (let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] diff --git a/test/monger/test/collection.clj b/test/monger/test/collection.clj index dad1b85..88b4d3b 100644 --- a/test/monger/test/collection.clj +++ b/test/monger/test/collection.clj @@ -384,7 +384,7 @@ ;; -;; exists?, drop +;; exists?, drop, create ;; (deftest checking-for-collection-existence-when-it-does-not-exist @@ -397,4 +397,10 @@ (monger.collection/drop collection) (monger.collection/insert-batch collection [{ :name "widget1" } { :name "widget2" }]) - (is (monger.collection/exists? collection)))) \ No newline at end of file + (is (monger.collection/exists? collection)) + (monger.collection/drop collection) + (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