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

FindOne() doesn't find one with nil filter

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Major - P3 Major - P3
    • None
    • 1.0.1, 1.0.0
    • CRUD
    • None
    • Linux, Go 1.12.4, Mongo Docker container created 2019-04-12T00:21:50.281225741Z

    Description

      I was writing code to just grab a TODO item with no filter, but kept getting no document. I was able to easily reproduce with the Trainer example; here's a snippet:

      // create a value into which the result can be decoded
      var result Trainer

      //err = collection.FindOne(context.TODO(), filter).Decode(&result)
      err = collection.FindOne(context.TODO(), nil).Decode(&result)
      if err != nil

      { log.Fatal(err) }

      With nil for filter:
      2019/04/24 10:41:32 document is nil

      If I connect using mongo shell:
      > db.trainers.findOne()

      { "_id" : "ash", "name" : "Ash", "age" : 11, "city" : "Pallet Town" }

      I'm working around by supplying a filter that's true for all records.

      Attachments

        Activity

          People

            divjot.arora@mongodb.com Divjot Arora (Inactive)
            parsley42 David L. Parsley
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: