Skip to content

Commit 11083c5

Browse files
Update README.md (#2176)
Co-authored-by: Preston Vasquez <[email protected]>
1 parent c66ea40 commit 11083c5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Make sure to defer a call to `Disconnect` after instantiating your client:
6363

6464
```go
6565
defer func() {
66-
if err = client.Disconnect(ctx); err != nil {
66+
if err := client.Disconnect(ctx); err != nil {
6767
panic(err)
6868
}
6969
}()
@@ -75,7 +75,7 @@ Calling `Connect` does not block for server discovery. If you wish to know if a
7575
use the `Ping` method:
7676

7777
```go
78-
ctx, cancel = context.WithTimeout(context.Background(), 2*time.Second)
78+
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
7979
defer cancel()
8080

8181
_ = client.Ping(ctx, readpref.Primary())
@@ -90,7 +90,7 @@ collection := client.Database("testing").Collection("numbers")
9090
The `Collection` instance can then be used to insert documents:
9191

9292
```go
93-
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
93+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
9494
defer cancel()
9595

9696
res, _ := collection.InsertOne(ctx, bson.D{{"name", "pi"}, {"value", 3.14159}})
@@ -117,7 +117,7 @@ import (
117117
Several query methods return a cursor, which can be used like this:
118118

119119
```go
120-
ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
120+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
121121
defer cancel()
122122

123123
cur, err := collection.Find(ctx, bson.D{})
@@ -148,10 +148,10 @@ var result struct {
148148
}
149149

150150
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)
152152
defer cancel()
153153

154-
err = collection.FindOne(ctx, filter).Decode(&result)
154+
err := collection.FindOne(ctx, filter).Decode(&result)
155155
if errors.Is(err, mongo.ErrNoDocuments) {
156156
// Do something when no record was found
157157
} else if err != nil {

0 commit comments

Comments
 (0)