Thin idiomatic wrapper around MongoDB Java client. monger.core includes fundamental functions that perform database/replica set connection, set default write concern, default database, performing commands and so on. Most of the functionality is in other monger.* namespaces, in particular monger.collection, monger.query and monger.gridfs
Related documentation guides:
Thin idiomatic wrapper around MongoDB Java client. monger.core includes fundamental functions that perform database/replica set connection, set default write concern, default database, performing commands and so on. Most of the functionality is in other monger.* namespaces, in particular monger.collection, monger.query and monger.gridfs Related documentation guides: * http://clojuremongodb.info/articles/connecting.html * http://clojuremongodb.info/articles/commands.html * http://clojuremongodb.info/articles/gridfs.html
(authenticate username password)
(authenticate db username password)
(authenticate connection db username password)
(command cmd)
(command database cmd)
Runs a database command (please check MongoDB documentation for the complete list of commands).
Ordering of keys in the command document may matter. Please use sorted maps instead of map literals, for example: (sorted-map geoNear "bars" :near 50 :test 430 :num 10)
For commonly used commands (distinct, count, map/reduce, etc), use monger.command and monger.collection functions such as /distinct, /count, /drop, /dropIndexes, and /mapReduce respectively.
Runs a database command (please check MongoDB documentation for the complete list of commands). Ordering of keys in the command document may matter. Please use sorted maps instead of map literals, for example: (sorted-map geoNear "bars" :near 50 :test 430 :num 10) For commonly used commands (distinct, count, map/reduce, etc), use monger.command and monger.collection functions such as /distinct, /count, /drop, /dropIndexes, and /mapReduce respectively.
(connect)
(connect {:keys [host port uri] :or {host *mongodb-host* port *mongodb-port*}})
(connect server-address options)
(connect [server-address & more] options)
Connects to MongoDB. When used without arguments, connects to
Arguments: :host (mongodb-host by default) :port (mongodb-port by default)
EXAMPLES
(monger.core/connect)
(monger.core/connect { :host "db3.intranet.local", :port 27787 })
;; Connecting to a replica set with a couple of seeds
(let [^MongoClientOptions opts (mg/mongo-options :threads-allowed-to-block-for-connection-multiplier 300)
seeds [["192.168.1.1" 27017] ["192.168.1.2" 27017] ["192.168.1.1" 27018]]
sas (map #(apply mg/server-address %) seeds)]
(mg/connect! sas opts))
Connects to MongoDB. When used without arguments, connects to Arguments: :host (*mongodb-host* by default) :port (*mongodb-port* by default) EXAMPLES (monger.core/connect) (monger.core/connect { :host "db3.intranet.local", :port 27787 }) ;; Connecting to a replica set with a couple of seeds (let [^MongoClientOptions opts (mg/mongo-options :threads-allowed-to-block-for-connection-multiplier 300) seeds [["192.168.1.1" 27017] ["192.168.1.2" 27017] ["192.168.1.1" 27018]] sas (map #(apply mg/server-address %) seeds)] (mg/connect! sas opts))
(connect! & args)
Connect to MongoDB, store connection in the mongodb-connection var
Connect to MongoDB, store connection in the *mongodb-connection* var
(connect-via-uri! uri-string)
Connects to MongoDB using a URI, sets up default connection and database. Commonly used for PaaS-based applications, for example, running on Heroku. If username and password are provided, performs authentication.
Connects to MongoDB using a URI, sets up default connection and database. Commonly used for PaaS-based applications, for example, running on Heroku. If username and password are provided, performs authentication.
(count this)
Returns size of the object
Returns size of the object
(current-db)
Returns currently used database
Returns currently used database
(disconnect!)
Closes default connection to MongoDB
Closes default connection to MongoDB
(get-db)
(get-db name)
(get-db connection name)
Get database reference by name.
EXAMPLES
(monger.core/get-db "myapp_production")
(monger.core/get-db connection "myapp_production")
Get database reference by name. EXAMPLES (monger.core/get-db "myapp_production") (monger.core/get-db connection "myapp_production")
(get-db-names)
(get-db-names connection)
Gets a list of all database names present on the server
Gets a list of all database names present on the server
(get-last-error)
(get-last-error database)
(get-last-error database write-concern)
(get-last-error database w wtimeout fsync)
Returns the the error (if there is one) from the previous operation on this connection.
The result of this command looks like:
#<CommandResult { "serverUsed" : "127.0.0.1:27017" , "n" : 0 , "connectionId" : 66 , "err" : null , "ok" : 1.0}>"
The value for err will be null if no error occurred, or a description otherwise.
Important note: when calling this method directly, it is undefined which connection "getLastError" is called on. You may need to explicitly use a "consistent Request", see requestStart() For most purposes it is better not to call this method directly but instead use WriteConcern.
Returns the the error (if there is one) from the previous operation on this connection. The result of this command looks like: #<CommandResult { "serverUsed" : "127.0.0.1:27017" , "n" : 0 , "connectionId" : 66 , "err" : null , "ok" : 1.0}>" The value for err will be null if no error occurred, or a description otherwise. Important note: when calling this method directly, it is undefined which connection "getLastError" is called on. You may need to explicitly use a "consistent Request", see requestStart() For most purposes it is better not to call this method directly but instead use WriteConcern.
(mongo-options &
{:keys [connections-per-host
threads-allowed-to-block-for-connection-multiplier
max-wait-time connect-timeout socket-timeout
socket-keep-alive auto-connect-retry
max-auto-connect-retry-time description write-concern
cursor-finalizer-enabled]
:or [auto-connect-retry true]})
(set-connection! conn)
Sets given MongoDB connection as default by altering mongodb-connection var
Sets given MongoDB connection as default by altering *mongodb-connection* var
(set-db! db)
Sets mongodb-database var to given db, updates mongodb-gridfs var state. Recommended to be used for applications that only use one database.
Sets *mongodb-database* var to given db, updates *mongodb-gridfs* var state. Recommended to be used for applications that only use one database.
Combines set-db! and get-db, so (use-db "mydb") is the same as (set-db! (get-db "mydb"))
Combines set-db! and get-db, so (use-db "mydb") is the same as (set-db! (get-db "mydb"))
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close