FindOne() doesn't find one with nil filter

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: 1.0.1, 1.0.0
    • Component/s: CRUD
    • None
    • Environment:
      Linux, Go 1.12.4, Mongo Docker container created 2019-04-12T00:21:50.281225741Z
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            Divjot Arora (Inactive)
            Reporter:
            David L. Parsley
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: