Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-10338

findOneAndUpdate (and findAndModify) needs sample code for how to do non-updating upserts

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Do
    • Icon: Major - P3 Major - P3
    • Server_Docs_20231030
    • None
    • manual
    • None

    Description

      If you want to use findOneAndUpdate (which is just a wrapper for findAndModify) to:

      • search for a document matching filter conditions {f1:v1, f2:v2, ...}
      • if it is not found, insert one and return it
      • if it is found, return it without updating it

      it is not clear in our documentation how to achieve that.

      This can be fixed by adding an example at the appropriate places in the docs that explains if both the <query> and <update> parameters to findOneAndUpdate are set to the same set of key:value equality conditions {f1:v1, f2:v2, ...}, then the existing document will not be updated.

      Attachments

        Activity

          People

            Unassigned Unassigned
            william.byrne@mongodb.com William Byrne III
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              1 year, 14 weeks, 2 days ago