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

Add Find/Update/Delete by _id helpers

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Go Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Context

      It's very common to want to call {{FindOne(bson.D

      {"_id", idVal}

      )}}, and fairly common to also to update, replace, or delete one doc based on the ID. In these cases, it'd be nice to have a helper that just took the ID value:

      func (coll *Collection) FindOneByID(id any, opts ...*options.FindOneOptions) *SingleResult {
          return coll.FindOne(bson.D{{"_id", id}})
      }
      

      Besides being convenient, it also eliminates the potential for typos, like using "id" instead of "_id".

      Definition of done

      Add at least the proposed FindOneByID method. I think the others would be used less. OTOH, they're all equally trivial to add.

      Pitfalls

      I can't think of any.

            Assignee:
            Unassigned Unassigned
            Reporter:
            dave.rolsky@mongodb.com Dave Rolsky
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: