Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-776

Passing "nil" as a filter

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 0.2.0
    • Component/s: Documentation
    • None
    • Environment:
      Operating system:macOS Mojave ver 10.14.2
      Golang version: go1.11.4 darwin/amd64

      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.

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            donald.casson Donald Casson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: