forked from mongodb/mongo-go-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.go
46 lines (46 loc) · 1.73 KB
/
doc.go
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
// Package mongo provides a MongoDB Driver API for Go.
//
// Basic usage of the driver starts with creating a Client from a connection
// string. To do so, call the NewClient function:
//
// client, err := mongo.NewClient("mongodb://foo:bar@localhost:27017")
// if err != nil { log.Fatal(err) }
//
// This will create a new client and start monitoring the MongoDB server on localhost.
// The Database and Collection types can be used to access the database:
//
// collection := client.Database("baz").Collection("qux")
//
// A Collection can be used to query the database or insert documents:
//
// res, err := collection.InsertOne(context.Background(), map[string]string{"hello": "world"})
// if err != nil { log.Fatal(err) }
// id := res.InsertedID
//
// Several methods return a cursor, which can be used like this:
//
// cur, err := collection.Find(context.Background(), nil)
// if err != nil { log.Fatal(err) }
// defer cur.Close(context.Background())
// for cur.Next(context.Background()) {
// elem := bson.NewDocument()
// err := cur.Decode(elem)
// if err != nil { log.Fatal(err) }
// // do something with elem....
// }
// if err := cur.Err(); err != nil {
// log.Fatal(err)
// }
//
// Methods that only return a single document will return a *DocumentResult, which works
// like a *sql.Row:
//
// result := bson.NewDocument()
// filter := bson.NewDocument(bson.EC.String("hello", "world"))
// err := collection.FindOne(context.Background(), filter).Decode(result)
// if err != nil { log.Fatal(err) }
// // do something with result...
//
// Additional examples can be found under the examples directory in the driver's repository and
// on the MongoDB website.
package mongo