[GODRIVER-776] Passing "nil" as a filter Created: 21/Jan/19  Updated: 29/Jan/19  Resolved: 28/Jan/19

Status: Closed
Project: Go Driver
Component/s: Documentation
Affects Version/s: 0.2.0
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Donald Casson Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating system:macOS Mojave ver 10.14.2
Golang version: go1.11.4 darwin/amd64


Issue Links:
Duplicate
duplicates GODRIVER-757 README out of date WRT using nil in Find Closed

 Description   

All the documentation and examples given describe a nil type can be passed as a parameter however when doing so the output is: 

 

 

$ go run main.go 
ID ObjectID("5c454e3cfd1361d7957038bf")
2019/01/21 14:44:44 bigerr: %sdocument is nil
exit status 1

 

The error comes from a call to collection.Find()

 
 

// cant pass nil     
// filter := bson.D{}
cur, err := collection.Find(context.Background(), nil)     
if err != nil {
         log.Fatal("bigerr: %s", err)     
}

 

 

collection.Find() passes the filter value downard to transformDocument()

https://github.com/mongodb/mongo-go-driver/blob/5514df920614a2ffba26ec3539d8509e8ad2344e/mongo/mongo.go#L133
 
 

And subsequently it is checked and if the value is nil it is returned. 

 

 
 
if val == nil {         return nil, ErrNilDocument     } 

 
 

It would make sense to be able to pass a nil to filter to get all the results from a colleciton however passing an empty bson.D{} object works also.

 



 Comments   
Comment by Dylan Parker [ 28/Jan/19 ]

I've got a PR open on github that updates the readme. You can find here https://github.com/mongodb/mongo-go-driver/pull/134

Comment by Ian Whalen (Inactive) [ 28/Jan/19 ]

Yup, as per your last comment - dupe of GODRIVER-757. divjot.arora please remember to update the readme in your PR too.

Comment by Donald Casson [ 21/Jan/19 ]

Looks like this has already been picked up and the readme needs to be updated.

Generated at Thu Feb 08 08:34:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.