forked from mikejs/gomongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
47 lines (32 loc) · 1.05 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
=======
gomongo
=======
Go driver for `MongoDB`_, a document based database which is being used in
`production`_ with great success.
Read this `article` to know more.
.. _MongoDB: http://www.mongodb.org/
.. _production: http://www.mongodb.org/display/DOCS/Production+Deployments
.. _article: http://go.hokapoka.com/golang/mongodb-golang-gomongo/
Installation
============
The easiest way to install it's through `goinstall` which automatically installs
the third libraries::
$ [sudo -E] goinstall github.com/mikejs/gomongo/mongo
Example usage
-------------
package main
import "github.com/mikejs/gomongo/mongo"
func main() {
conn, _ := mongo.Connect("127.0.0.1")
collection := conn.GetDB("test").GetCollection("test_collection")
doc, _ := mongo.Marshal(map[string]string{
"_id": "doc1",
"title": "A Mongo document",
"content": "Testing, 1. 2. 3.",
})
collection.Insert(doc)
query, _ := mongo.Marshal(map[string]string{"_id": "doc1"})
got, _ := collection.FindOne(query)
mongo.Equal(doc, got) // true!
collection.Drop()
}