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

$setOnInsert should allow _id to be set

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.4
    • Affects Version/s: None
    • Component/s: Write Ops
    • None

      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.

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            gjroylance Gordon Roylance
            Votes:
            6 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: