Skip to content

Commit bfa2f91

Browse files
committed
Makes code forward compatible up to 0.3.0
Replaces nil documents with bson.D{{}}. Also removes accidental renaming of options package. Fixes #2.
1 parent beaecf5 commit bfa2f91

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,14 @@ To find multiple documents, use `collection.Find()`. This method returns a `Curs
211211

212212
```go
213213
// Pass these options to the Find method
214-
options := options.Find()
215-
options.SetLimit(2)
214+
findOptions := options.Find()
215+
findOptions.SetLimit(2)
216216

217217
// Here's an array in which you can store the decoded documents
218218
var results []*Trainer
219219

220-
// Passing nil as the filter matches all documents in the collection
221-
cur, err := collection.Find(context.TODO(), nil, options)
220+
// Passing bson.D{{}} as the filter matches all documents in the collection
221+
cur, err := collection.Find(context.TODO(), bson.D{{}}, findOptions)
222222
if err != nil {
223223
log.Fatal(err)
224224
}
@@ -249,10 +249,10 @@ fmt.Printf("Found multiple documents (array of pointers): %+v\n", results)
249249

250250
### Delete Documents
251251

252-
Finally, you can delete documents using `collection.DeleteOne()` or `collection.DeleteMany()`. Here you pass `nil` as the filter argument, which will match all documents in the collection. You could also use [`collection.Drop()`](https://godoc.org/github.com/mongodb/mongo-go-driver/mongo#Collection.Drop) to delete an entire collection.
252+
Finally, you can delete documents using `collection.DeleteOne()` or `collection.DeleteMany()`. Here you pass `bson.D{{}}` as the filter argument, which will match all documents in the collection. You could also use [`collection.Drop()`](https://godoc.org/github.com/mongodb/mongo-go-driver/mongo#Collection.Drop) to delete an entire collection.
253253

254254
```go
255-
deleteResult, err := collection.DeleteMany(context.TODO(), nil)
255+
deleteResult, err := collection.DeleteMany(context.TODO(), bson.D{{}})
256256
if err != nil {
257257
log.Fatal(err)
258258
}

main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,13 @@ func main() {
8181

8282
fmt.Printf("Found a single document: %+v\n", result)
8383

84-
// Add extra options to queries using the options package
85-
options := options.Find()
86-
options.SetLimit(2)
84+
findOptions := options.Find()
85+
findOptions.SetLimit(2)
8786

8887
var results []*Trainer
8988

9089
// Finding multiple documents returns a cursor
91-
cur, err := collection.Find(context.TODO(), nil, options)
90+
cur, err := collection.Find(context.TODO(), bson.D{{}}, findOptions)
9291
if err != nil {
9392
log.Fatal(err)
9493
}
@@ -114,10 +113,11 @@ func main() {
114113
fmt.Printf("Found multiple documents (array of pointers): %+v\n", results)
115114

116115
// Delete all the documents in the collection
117-
deleteResult, err := collection.DeleteMany(context.TODO(), nil)
116+
deleteResult, err := collection.DeleteMany(context.TODO(), bson.D{{}})
118117
if err != nil {
119118
log.Fatal(err)
120119
}
120+
121121
fmt.Printf("Deleted %v documents in the trainers collection\n", deleteResult.DeletedCount)
122122

123123
// Close the connection once no longer needed

0 commit comments

Comments
 (0)