Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-1182

Add $noop operation to update or another insert if not exist feature

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • 1.5.2
    • Querying
    • None

    Description

      Add a $noop operations so you can effectively do an insert if some criteria doesn't already exist.

      db.coll.update({_id:25, name:"John"}, {$noop:1}, true, false)

      This question came up in IRC and is the reason for this request: "I want to insert some data into a collection if and only if it doesn't exist already?"

      This can be done with a query + insert but would be closer to the RDBMS version (which is wrapped in a transaction normally) using the syntax above (which is atomic).

      I could also see this working by using a null second param for update (this is not currently allowed), but the $noop is clearer.

      Attachments

        Activity

          People

            eliot Eliot Horowitz (Inactive)
            scotthernandez Scott Hernandez (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: