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

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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Needs Triage
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: manual
    • Labels:
      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

            Assignee:
            Unassigned Unassigned
            Reporter:
            william.byrne William Byrne III
            Participants:
            Last commenter:
            Anthony Sansone Anthony Sansone
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Days since reply:
              4 years, 27 weeks, 2 days ago