Add monger.collection/system-collection?, a convenience function
We don't add it to the change log because the majority of apps won't use it and it is not an important change between RC1 and RC2 (or what may even be 1.0).
This commit is contained in:
parent
e481b1ca84
commit
75bb240af9
2 changed files with 33 additions and 0 deletions
|
|
@ -612,3 +612,17 @@
|
||||||
;; this is what DBCollection#distinct does. Turning a blind eye!
|
;; this is what DBCollection#distinct does. Turning a blind eye!
|
||||||
(.throwOnError res)
|
(.throwOnError res)
|
||||||
(map #(from-db-object % true) (.get res "result"))))
|
(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))
|
||||||
|
|
|
||||||
|
|
@ -132,3 +132,22 @@
|
||||||
(mc/insert-batch collection batch)
|
(mc/insert-batch collection batch)
|
||||||
(is (= ["CA" "IL" "NY"] (sort (mc/distinct mg/*mongodb-database* collection :state {}))))
|
(is (= ["CA" "IL" "NY"] (sort (mc/distinct mg/*mongodb-database* collection :state {}))))
|
||||||
(is (= ["CA" "NY"] (sort (mc/distinct collection :state {:price {$gt 100.00}}))))))
|
(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"))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue