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

$setOnInsert should allow _id to be set

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5.4
    • Component/s: Write Ops
    • Labels:
      None

      Description

      Allow setting the _id field if an update does an insert (upsert true case).

      Original Description:
      Unable to specify a custom id for the new record using $setOnInsert when calling findAndModify() or update() with upsert = true using a query that does not include the _id. In our scenario the _id is not known before hand, so an additional query has to be used before calling update() or findAndModity() which breaks the atomic nature of the original query. The query worked fine before we wanted to control the _id. When attempting to call db.col.update(

      {"name":"test"}

      ,{$setOnInsert: {_id:"12345"}},

      {upsert: true}

      ) we receive the error: Mod on _id not allowed. This doesn't make sense since the record is being created and _id should not already exist.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                6 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: