From f2a5786ad4faaf6bbddfff0018b9eb96271cef6a Mon Sep 17 00:00:00 2001 From: Oleksandr Petrov Date: Wed, 30 Nov 2011 22:07:40 +0100 Subject: [PATCH] Adding some docs. --- docs/querying.md | 80 ++++++++++++++++++++++++++++++++++++++++++++- src/monger/core.clj | 4 ++- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/docs/querying.md b/docs/querying.md index 0506f4d..5755acf 100644 --- a/docs/querying.md +++ b/docs/querying.md @@ -16,5 +16,83 @@ Monger users several dynamic variables to simplify your common workflows: - *mongodb-port* - *mongodb-connection* - *mongodb-database* - - *mongodb-write-concern* (we recommend to use WriteConcern/SAFE by default to make sure your data was written) + - *mongodb-write-concern* (we recommend to use WriteConcern/SAFE by default to make sure your data was written + +You can work with as many connections as you want, but since most use-cases are for just one database, Monger provides *mongodb-connection* and *mongodb-database* to make it easier for you to connect. In order to perform an initial connection, simply do: + + (monger.core/connect!) + (monger.core/set-db! (monger.core/get-db "database-name")) + +This will connect you to MongoDB server on localhost, port 27071, set that connection to *mongodb-connection*, and create DB entity for "database-name" and preserve it in *mongodb-database*. + +If you have more than one database to connect, use monger.core/connect and monger.core/set-db! accordingly. + + (let [ default-mongodb-connection (monger.core/connect) + my-first-database (monger.core/get-db "my-first-database-name") + + nonlocal-mongodb-connection (monger.core/connect :host "my-mongo-server.local") + my-second-database (monger.core/get-db "my-second-database-name") ]) + +So, now you have 2 connections and 2 databases, you can manipulate them independently. + +# Working with collections + +Monger is made to make your common workflows easier. You can use power of clojure maps to write and query your data. monger.conversions namespace contains several protocols that allow you to convert Clojure data to BasicDBObject that's used by MongoDB Java driver and back. Most of time you don't have to call them directly, but if you implement some more complex workflows, you may possibly need them. + + +## drop +## create +## exists? + +## Query syntax + +If you know how to use MongoDB console, you already know how to write Monger queries. In order to start writing queries, you need to know syntax for arrays, maps and operatros. + + { :language "Clojure" } + ;; { language: "Clojure"} + + { :tags { $all [ "functional" "object-oriented" ] } } + ;; { $all: [ "functional", "object-oriented" ] } + +## Querying collections + +### find +### find-one +### find-by-id +### count +### distinct + +### Query operators + +## Inserting records + +### Single +### Batch + +## remove + +## update + +### Atomic modifiers + +## save + +# Indexing + +## Creating index on the collection + +## GeoSpatial Indices + + +# Map/Reduce + +# Working with Dates, Joda Time + +# Working with commands + +# Replica Sets + +# Shards + +When working with shards, you don't have to make your client to be aware of them. They are transparent and invisible to client, and everything is handled by mongos. diff --git a/src/monger/core.clj b/src/monger/core.clj index 510f64a..4943eb1 100644 --- a/src/monger/core.clj +++ b/src/monger/core.clj @@ -90,7 +90,9 @@ (defn set-default-write-concern! [wc] - "Set dynamic *mongodb-write-concert* to :wc" + "Set dynamic *mongodb-write-concert* to :wc + + We recommend to use WriteConcern/SAFE by default to make sure your data was written." (def ^:dynamic *mongodb-write-concern* wc)) (defn command