diff --git a/src/monger/collection.clj b/src/monger/collection.clj index 592720d..0eaa4fc 100644 --- a/src/monger/collection.clj +++ b/src/monger/collection.clj @@ -612,3 +612,17 @@ ;; this is what DBCollection#distinct does. Turning a blind eye! (.throwOnError res) (map #(from-db-object % true) (.get res "result")))) + + +;; +;; Misc +;; + +(def ^{:const true} + system-collection-pattern #"^(system|fs)") + +(defn- system-collection? + "Evaluates to true if the given collection name refers to a system collection. System collections + are prefixed with system. or fs. (default GridFS collection prefix)" + [^String coll-name] + (re-find system-collection-pattern coll-name)) diff --git a/test/monger/test/collection_test.clj b/test/monger/test/collection_test.clj index 27349b2..5644cc5 100644 --- a/test/monger/test/collection_test.clj +++ b/test/monger/test/collection_test.clj @@ -132,3 +132,22 @@ (mc/insert-batch collection batch) (is (= ["CA" "IL" "NY"] (sort (mc/distinct mg/*mongodb-database* collection :state {})))) (is (= ["CA" "NY"] (sort (mc/distinct collection :state {:price {$gt 100.00}})))))) + + +;; +;; miscellenous +;; + +(deftest test-system-collection-predicate + (are [name] (is (mc/system-collection? name)) + "system.indexes" + "system" + ;; we treat default GridFS collections as system ones, + ;; possibly this is a bad idea, time will tell. MK. + "fs.chunks" + "fs.files") + (are [name] (is (not (mc/system-collection? name))) + "events" + "accounts" + "megacorp_account" + "myapp_development"))