Permalink
Browse files

Merge pull request #40 from hozumi/master

Better markdown formatting for readme
  • Loading branch information...
2 parents b52c97e + 07a4160 commit 1e10103b8d0a8a8e7d8ec3af751efed7da9de887 @purcell purcell committed Nov 9, 2011
Showing with 79 additions and 75 deletions.
  1. +79 −75 readme.markdown
View
@@ -48,113 +48,117 @@ Basics
### Setup
#### import
-
- (ns my-mongo-app
- (:use somnium.congomongo))
-
+```clojure
+(ns my-mongo-app
+ (:use somnium.congomongo))
+```
#### make a connection
+```clojure
+(def conn mongo/make-connection "mydb"
+ :host "127.0.0.1"
+ :port 27017) => #'user/conn
- (def conn mongo/make-connection "mydb"
- :host "127.0.0.1"
- :port 27017) => #'user/conn
-
- conn => {:mongo #<Mongo Mongo: 127.0.0.1:20717>, :db #<DBApiLayer mydb>}
-
+conn => {:mongo #<Mongo Mongo: 127.0.0.1:20717>, :db #<DBApiLayer mydb>}
+```
#### set the connection globally
-
- (set-connection! conn)
-
+```clojure
+(set-connection! conn)
+```
#### or locally
-
- (with-mongo conn
- (insert! :robots {:name "robby"}))
-
+```clojure
+(with-mongo conn
+ (insert! :robots {:name "robby"}))
+```
### Simple Tasks
------------------
#### create
-
- (insert! :robots
- {:name "robby"}
-
+```clojure
+(insert! :robots
+ {:name "robby"}
+```
#### read
- (def my-robot (fetch-one :robots)) => #'user/my-robot
-
- my-robot => { :name "robby",
- :_id #<ObjectId> "0c23396f7e53e34a4c8cf400">,
- :_ns "robots"}
-
+(def my-robot (fetch-one :robots)) => #'user/my-robot
+```clojure
+my-robot => { :name "robby",
+ :_id #<ObjectId> "0c23396f7e53e34a4c8cf400">,
+ :_ns "robots"}
+```
#### update
+```clojure
+(update! :robots my-robot (merge my-robot { :name "asimo" }))
- (update! :robots my-robot (merge my-robot { :name "asimo" }))
-
- => { :name "asimo" ,
- :_id #<ObjectId> "0c23396f7e53e34a4c8cf400"> ,
- :_ns : "robots" }
-
+=> { :name "asimo" ,
+ :_id #<ObjectId> "0c23396f7e53e34a4c8cf400"> ,
+ :_ns : "robots" }
+```
#### destroy
-
- (destroy! :robots my-robot) => nil
- (fetch :robots) => ()
-
+```clojure
+(destroy! :robots my-robot) => nil
+(fetch :robots) => ()
+```
### More Sophisticated Tasks
----------------------------
#### mass inserts
-
- (mass-insert!
- :points
- (for [x (range 100) y (range 100)]
- {:x x
- :y y
- :z (* x y)}))
-
- => nil
-
- (fetch-count :points)
- => 10000
-
+```clojure
+(mass-insert!
+ :points
+ (for [x (range 100) y (range 100)]
+ {:x x
+ :y y
+ :z (* x y)}))
+
+ => nil
+
+(fetch-count :points)
+=> 10000
+```
#### ad-hoc queries
-
- (fetch-one
- :points
- :where {:x {:$gt 10
- :$lt 20}
- :y 42
- :z {:$gt 500}})
-
- => {:x 12, :y 42, :z 504, :_ns "points", :_id ... }
-
+```clojure
+(fetch-one
+ :points
+ :where {:x {:$gt 10
+ :$lt 20}
+ :y 42
+ :z {:$gt 500}})
+
+=> {:x 12, :y 42, :z 504, :_ns "points", :_id ... }
+```
#### authentication
+```clojure
+(authenticate conn "myusername" "my password")
- (authenticate conn "myusername" "my password")
-
- => true
-
+=> true
+```
#### advanced initialization using mongo-options
-
- ((make-connection :mydb :host "127.0.0.1" (mongo-options :auto-connect-retry true)"
-
+```clojure
+((make-connection :mydb :host "127.0.0.1" (mongo-options :auto-connect-retry true)"
+```
#### easy json
------------------------------------------------------------------------
+```clojure
+(fetch-one :points
+ :as :json)
- (fetch-one :points
- :as :json)
+=> "{ \"_id\" : \"0c23396ffe79e34a508cf400\" ,
+ \"x\" : 0 , \"y\" : 0 , \"z\" : 0 , \"_ns\" : \"points\"}"
+```
- => "{ \"_id\" : \"0c23396ffe79e34a508cf400\" ,
- \"x\" : 0 , \"y\" : 0 , \"z\" : 0 , \"_ns\" : \"points\"}"
-
-
Install
-------
Leiningen is the recommended way to use congomongo.
-Just add
+Just add
+
[congomongo "0.1.7"]
+
to your project.clj and do
+
$lein deps
-to get congomongo and all of its dependencies.
+
+to get congomongo and all of its dependencies.
### Feedback

0 comments on commit 1e10103

Please sign in to comment.