Add support for index options + unique indexes for monger.collection/ensure-index and monger.collection/create-index
This commit is contained in:
parent
576f264e97
commit
0530b165f6
5 changed files with 28 additions and 10 deletions
|
|
@ -1,5 +1,11 @@
|
||||||
## Changes between 1.0.0-beta2 and 1.0.0-beta3
|
## Changes between 1.0.0-beta2 and 1.0.0-beta3
|
||||||
|
|
||||||
|
### Index Options support for monger.collection/ensure-index and /create-index
|
||||||
|
|
||||||
|
`monger.collection/ensure-index` and `/create-index` now accept index options as additional argument.
|
||||||
|
**Breaking change**: 3-arity versions of those functions now become 4-arity versions.
|
||||||
|
|
||||||
|
|
||||||
### Support serialization of Clojure ratios
|
### Support serialization of Clojure ratios
|
||||||
|
|
||||||
Documents that contain Clojure ratios (for example, `26/5`) now can be converted to DBObject instances
|
Documents that contain Clojure ratios (for example, `26/5`) now can be converted to DBObject instances
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,11 @@
|
||||||
:dependencies [[org.clojure/clojure "1.3.0"]
|
:dependencies [[org.clojure/clojure "1.3.0"]
|
||||||
[org.mongodb/mongo-java-driver "2.7.3"]
|
[org.mongodb/mongo-java-driver "2.7.3"]
|
||||||
[com.novemberain/validateur "1.0.0"]]
|
[com.novemberain/validateur "1.0.0"]]
|
||||||
:test-selectors {:focus (fn [v] (:focus v))}
|
:test-selectors {:default (complement :performance)
|
||||||
|
:focus :focus
|
||||||
|
:indexing :indexing
|
||||||
|
:performance :performance
|
||||||
|
:all (constantly true)}
|
||||||
:codox {:exclude [monger.internal.pagination]}
|
:codox {:exclude [monger.internal.pagination]}
|
||||||
:mailing-list {:name "clojure-monger",
|
:mailing-list {:name "clojure-monger",
|
||||||
:archive "https://groups.google.com/group/clojure-monger",
|
:archive "https://groups.google.com/group/clojure-monger",
|
||||||
|
|
|
||||||
|
|
@ -388,16 +388,20 @@
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
|
|
||||||
;; Will create an index on \"language\" field
|
;; Will create an index on the \"language\" field
|
||||||
(monger.collection/create-index collection { \"language\" 1 })
|
(monger.collection/create-index collection { \"language\" 1 })
|
||||||
|
(monger.collection/create-index collection { \"language\" 1 } { :unique true :name \"unique_language\" })
|
||||||
|
|
||||||
"
|
"
|
||||||
([^String collection ^Map keys]
|
([^String collection ^Map keys]
|
||||||
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)]
|
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)]
|
||||||
(.createIndex coll (to-db-object keys))))
|
(.createIndex coll (to-db-object keys))))
|
||||||
([^DB db ^String collection ^Map keys]
|
([^String collection ^Map keys options]
|
||||||
|
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)]
|
||||||
|
(.createIndex coll (to-db-object keys) (to-db-object options))))
|
||||||
|
([^DB db ^String collection ^Map keys ^Map options]
|
||||||
(let [^DBCollection coll (.getCollection db collection)]
|
(let [^DBCollection coll (.getCollection db collection)]
|
||||||
(.createIndex coll (to-db-object keys)))))
|
(.createIndex coll (to-db-object keys) (to-db-object options)))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
@ -416,9 +420,12 @@
|
||||||
([^String collection, ^Map keys]
|
([^String collection, ^Map keys]
|
||||||
(let [coll ^DBCollection (.getCollection monger.core/*mongodb-database* collection)]
|
(let [coll ^DBCollection (.getCollection monger.core/*mongodb-database* collection)]
|
||||||
(.ensureIndex ^DBCollection coll ^DBObject (to-db-object keys))))
|
(.ensureIndex ^DBCollection coll ^DBObject (to-db-object keys))))
|
||||||
([^String collection, ^Map keys, ^String name]
|
([^String collection, ^Map keys ^Map options]
|
||||||
(let [coll ^DBCollection (.getCollection monger.core/*mongodb-database* collection)]
|
(let [coll ^DBCollection (.getCollection monger.core/*mongodb-database* collection)]
|
||||||
(.ensureIndex coll ^DBObject (to-db-object keys) ^String name))))
|
(.ensureIndex ^DBCollection coll ^DBObject (to-db-object keys) (to-db-object options))))
|
||||||
|
([^String collection ^Map keys ^String name ^Boolean unique?]
|
||||||
|
(let [coll ^DBCollection (.getCollection monger.core/*mongodb-database* collection)]
|
||||||
|
(.ensureIndex coll ^DBObject (to-db-object keys) ^String name unique?))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@
|
||||||
;; indexes
|
;; indexes
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(deftest index-operations
|
(deftest ^{:indexing true} index-operations
|
||||||
(let [collection "libraries"]
|
(let [collection "libraries"]
|
||||||
(mgcol/drop-indexes collection)
|
(mgcol/drop-indexes collection)
|
||||||
(is (= "_id_"
|
(is (= "_id_"
|
||||||
|
|
@ -86,10 +86,11 @@
|
||||||
(:name (second (mgcol/indexes-on collection)))))
|
(:name (second (mgcol/indexes-on collection)))))
|
||||||
(mgcol/drop-index collection "language_1")
|
(mgcol/drop-index collection "language_1")
|
||||||
(is (nil? (second (mgcol/indexes-on collection))))
|
(is (nil? (second (mgcol/indexes-on collection))))
|
||||||
(mgcol/ensure-index collection { "language" 1 })
|
(mgcol/ensure-index collection { "language" 1 } {:unique true})
|
||||||
(is (= "language_1"
|
(is (= "language_1"
|
||||||
(:name (second (mgcol/indexes-on collection)))))
|
(:name (second (mgcol/indexes-on collection)))))
|
||||||
(mgcol/ensure-index collection { "language" 1 })))
|
(mgcol/ensure-index collection { "language" 1 })
|
||||||
|
(mgcol/ensure-index collection { "language" 1 } { :unique true })))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
(monger.core/set-default-write-concern! WriteConcern/NORMAL)
|
(monger.core/set-default-write-concern! WriteConcern/NORMAL)
|
||||||
|
|
||||||
(deftest insert-large-batches-of-documents-without-object-ids
|
(deftest ^{:performance true} insert-large-batches-of-documents-without-object-ids
|
||||||
(doseq [n [1000 10000 100000]]
|
(doseq [n [1000 10000 100000]]
|
||||||
(let [collection "things"
|
(let [collection "things"
|
||||||
docs (map (fn [i]
|
docs (map (fn [i]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue