commit
f64d085b0f
3 changed files with 29 additions and 21 deletions
|
|
@ -61,7 +61,8 @@
|
||||||
(:require [monger.core :as mc]
|
(:require [monger.core :as mc]
|
||||||
[monger.result :as mres]
|
[monger.result :as mres]
|
||||||
[monger.conversion :refer :all]
|
[monger.conversion :refer :all]
|
||||||
[monger.constraints :refer :all]))
|
[monger.constraints :refer :all]
|
||||||
|
[monger.util :refer [into-array-list]]))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
@ -450,9 +451,9 @@
|
||||||
(defn drop-index
|
(defn drop-index
|
||||||
"Drops an index from this collection."
|
"Drops an index from this collection."
|
||||||
[^DB db ^String coll idx]
|
[^DB db ^String coll idx]
|
||||||
(.dropIndex (.getCollection db (name coll)) (if (string? idx)
|
(if (string? idx)
|
||||||
idx
|
(.dropIndex (.getCollection db (name coll)) ^String idx)
|
||||||
(to-db-object idx))))
|
(.dropIndex (.getCollection db (name coll)) (to-db-object idx))))
|
||||||
|
|
||||||
(defn drop-indexes
|
(defn drop-indexes
|
||||||
"Drops all indixes from this collection."
|
"Drops all indixes from this collection."
|
||||||
|
|
@ -524,6 +525,7 @@
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(defn- build-aggregation-options
|
(defn- build-aggregation-options
|
||||||
|
^AggregationOptions
|
||||||
[{:keys [^Boolean allow-disk-use cursor ^Long max-time]}]
|
[{:keys [^Boolean allow-disk-use cursor ^Long max-time]}]
|
||||||
(cond-> (AggregationOptions/builder)
|
(cond-> (AggregationOptions/builder)
|
||||||
allow-disk-use (.allowDiskUse allow-disk-use)
|
allow-disk-use (.allowDiskUse allow-disk-use)
|
||||||
|
|
@ -543,7 +545,7 @@
|
||||||
[^DB db ^String coll stages & opts]
|
[^DB db ^String coll stages & opts]
|
||||||
(let [coll (.getCollection db coll)
|
(let [coll (.getCollection db coll)
|
||||||
agg-opts (build-aggregation-options opts)
|
agg-opts (build-aggregation-options opts)
|
||||||
pipe (java.util.ArrayList. (to-db-object stages))
|
pipe (into-array-list (to-db-object stages))
|
||||||
res (.aggregate coll pipe agg-opts)]
|
res (.aggregate coll pipe agg-opts)]
|
||||||
(map #(from-db-object % true) (iterator-seq res))))
|
(map #(from-db-object % true) (iterator-seq res))))
|
||||||
|
|
||||||
|
|
@ -554,7 +556,7 @@
|
||||||
[^DB db ^String coll stages & opts]
|
[^DB db ^String coll stages & opts]
|
||||||
(let [coll (.getCollection db coll)
|
(let [coll (.getCollection db coll)
|
||||||
agg-opts (build-aggregation-options opts)
|
agg-opts (build-aggregation-options opts)
|
||||||
pipe (java.util.ArrayList. (to-db-object stages))
|
pipe (into-array-list (to-db-object stages))
|
||||||
res (.explainAggregate coll pipe agg-opts)]
|
res (.explainAggregate coll pipe agg-opts)]
|
||||||
(from-db-object res true)))
|
(from-db-object res true)))
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
|
|
@ -42,11 +42,12 @@
|
||||||
* http://clojuremongodb.info/articles/commands.html
|
* http://clojuremongodb.info/articles/commands.html
|
||||||
* http://clojuremongodb.info/articles/gridfs.html"
|
* http://clojuremongodb.info/articles/gridfs.html"
|
||||||
(:refer-clojure :exclude [count])
|
(:refer-clojure :exclude [count])
|
||||||
(:require [monger.conversion :refer :all])
|
(:require [monger.conversion :refer :all]
|
||||||
|
[monger.util :refer [into-array-list]])
|
||||||
(:import [com.mongodb MongoClient MongoClientURI MongoCredential DB WriteConcern DBObject DBCursor Bytes
|
(:import [com.mongodb MongoClient MongoClientURI MongoCredential DB WriteConcern DBObject DBCursor Bytes
|
||||||
MongoClientOptions MongoClientOptions$Builder ServerAddress MapReduceOutput MongoException]
|
MongoClientOptions MongoClientOptions$Builder ServerAddress MapReduceOutput MongoException]
|
||||||
[com.mongodb.gridfs GridFS]
|
[com.mongodb.gridfs GridFS]
|
||||||
[java.util Map ArrayList]))
|
[java.util Map]))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Defaults
|
;; Defaults
|
||||||
|
|
@ -77,18 +78,18 @@
|
||||||
([server-address ^MongoClientOptions options]
|
([server-address ^MongoClientOptions options]
|
||||||
(if (coll? server-address)
|
(if (coll? server-address)
|
||||||
;; connect to a replica set
|
;; connect to a replica set
|
||||||
(let [server-list ^ArrayList (ArrayList. ^java.util.Collection server-address)]
|
(let [server-list (into-array-list server-address)]
|
||||||
(MongoClient. server-list options))
|
(MongoClient. server-list options))
|
||||||
;; connect to a single instance
|
;; connect to a single instance
|
||||||
(MongoClient. ^ServerAddress server-address options)))
|
(MongoClient. ^ServerAddress server-address options)))
|
||||||
([server-address ^MongoClientOptions options credentials]
|
([server-address ^MongoClientOptions options credentials]
|
||||||
(let [creds (if (coll? credentials)
|
(let [creds (into-array-list (if (coll? credentials)
|
||||||
credentials
|
credentials
|
||||||
[credentials])]
|
[credentials]))]
|
||||||
(if (coll? server-address)
|
(if (coll? server-address)
|
||||||
(let [server-list ^ArrayList (ArrayList. ^java.util.Collection server-address)]
|
(let [server-list (into-array-list server-address)]
|
||||||
(MongoClient. server-list creds options))
|
(MongoClient. server-list ^java.util.List creds options))
|
||||||
(MongoClient. ^ServerAddress server-address creds options))))
|
(MongoClient. ^ServerAddress server-address ^java.util.List creds options))))
|
||||||
([{ :keys [host port uri] :or { host *mongodb-host* port *mongodb-port* }}]
|
([{ :keys [host port uri] :or { host *mongodb-host* port *mongodb-port* }}]
|
||||||
(if uri
|
(if uri
|
||||||
(MongoClient. (MongoClientURI. uri))
|
(MongoClient. (MongoClientURI. uri))
|
||||||
|
|
@ -100,11 +101,11 @@
|
||||||
(connect-with-credentials *mongodb-host* *mongodb-port* credentials))
|
(connect-with-credentials *mongodb-host* *mongodb-port* credentials))
|
||||||
([^String hostname credentials]
|
([^String hostname credentials]
|
||||||
(connect-with-credentials hostname *mongodb-port* credentials))
|
(connect-with-credentials hostname *mongodb-port* credentials))
|
||||||
([^String hostname port credentials]
|
([^String hostname ^long port credentials]
|
||||||
(MongoClient. [(ServerAddress. hostname port)]
|
(MongoClient. (into-array-list [(ServerAddress. hostname port)])
|
||||||
(if (coll? credentials)
|
(into-array-list (if (coll? credentials)
|
||||||
credentials
|
credentials
|
||||||
[credentials]))))
|
[credentials])))))
|
||||||
|
|
||||||
(defn get-db-names
|
(defn get-db-names
|
||||||
"Gets a list of all database names present on the server"
|
"Gets a list of all database names present on the server"
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@
|
||||||
"Returns a new BSON object id, or converts str to BSON object id"
|
"Returns a new BSON object id, or converts str to BSON object id"
|
||||||
([]
|
([]
|
||||||
(ObjectId.))
|
(ObjectId.))
|
||||||
([s]
|
([^String s]
|
||||||
(ObjectId. s)))
|
(ObjectId. s)))
|
||||||
|
|
||||||
(defprotocol GetDocumentId
|
(defprotocol GetDocumentId
|
||||||
|
|
@ -73,3 +73,8 @@
|
||||||
(get-id
|
(get-id
|
||||||
[^IPersistentMap object]
|
[^IPersistentMap object]
|
||||||
(or (:_id object) (object "_id"))))
|
(or (:_id object) (object "_id"))))
|
||||||
|
|
||||||
|
(defn into-array-list
|
||||||
|
"Coerce a j.u.Collection into a j.u.ArrayList."
|
||||||
|
^java.util.ArrayList [^java.util.Collection coll]
|
||||||
|
(java.util.ArrayList. coll))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue