Skip to content

Commit

Permalink
fix README error handling of FindOne (mongodb#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
nullswan authored May 4, 2021
1 parent 8af0aac commit e0f4b3c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ cur, err := collection.Find(ctx, bson.D{})
if err != nil { log.Fatal(err) }
defer cur.Close(ctx)
for cur.Next(ctx) {
var result bson.D
err := cur.Decode(&result)
if err != nil { log.Fatal(err) }
// do something with result....
var result bson.D
err := cur.Decode(&result)
if err != nil { log.Fatal(err) }
// do something with result....
}
if err := cur.Err(); err != nil {
log.Fatal(err)
log.Fatal(err)
}
```

Expand All @@ -140,7 +140,7 @@ err = collection.FindOne(ctx, filter).Decode(&result)
if err == mongo.ErrNoDocuments {
// Do something when no record was found
fmt.Println("record does not exist")
} else {
} else if err != nil {
log.Fatal(err)
}
// Do something with result...
Expand Down

0 comments on commit e0f4b3c

Please sign in to comment.