@@ -63,7 +63,7 @@ Make sure to defer a call to `Disconnect` after instantiating your client:
63
63
64
64
``` go
65
65
defer func () {
66
- if err = client.Disconnect (ctx); err != nil {
66
+ if err : = client.Disconnect (ctx); err != nil {
67
67
panic (err)
68
68
}
69
69
}()
@@ -75,7 +75,7 @@ Calling `Connect` does not block for server discovery. If you wish to know if a
75
75
use the ` Ping ` method:
76
76
77
77
``` go
78
- ctx, cancel = context.WithTimeout (context.Background (), 2 *time.Second )
78
+ ctx , cancel : = context.WithTimeout (context.Background (), 2 *time.Second )
79
79
defer cancel ()
80
80
81
81
_ = client.Ping (ctx, readpref.Primary ())
@@ -90,7 +90,7 @@ collection := client.Database("testing").Collection("numbers")
90
90
The ` Collection ` instance can then be used to insert documents:
91
91
92
92
``` go
93
- ctx, cancel = context.WithTimeout (context.Background (), 5 *time.Second )
93
+ ctx , cancel : = context.WithTimeout (context.Background (), 5 *time.Second )
94
94
defer cancel ()
95
95
96
96
res , _ := collection.InsertOne (ctx, bson.D {{" name" , " pi" }, {" value" , 3.14159 }})
@@ -117,7 +117,7 @@ import (
117
117
Several query methods return a cursor, which can be used like this:
118
118
119
119
``` go
120
- ctx, cancel = context.WithTimeout (context.Background (), 30 *time.Second )
120
+ ctx , cancel : = context.WithTimeout (context.Background (), 30 *time.Second )
121
121
defer cancel ()
122
122
123
123
cur , err := collection.Find (ctx, bson.D {})
@@ -148,10 +148,10 @@ var result struct {
148
148
}
149
149
150
150
filter := bson.D {{" name" , " pi" }}
151
- ctx, cancel = context.WithTimeout (context.Background (), 5 *time.Second )
151
+ ctx , cancel : = context.WithTimeout (context.Background (), 5 *time.Second )
152
152
defer cancel ()
153
153
154
- err = collection.FindOne (ctx, filter).Decode (&result)
154
+ err : = collection.FindOne (ctx, filter).Decode (&result)
155
155
if errors.Is (err, mongo.ErrNoDocuments ) {
156
156
// Do something when no record was found
157
157
} else if err != nil {
0 commit comments