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

$setOnInsert prevents setting the _id

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Write Ops
    • ALL

      I need to insert a new document if it doesn't exist yet, or return an existing document if it already exists.

      db.projects.findAndModify({
          query: {parentProjectId: "project:522755ba0d8686aa6f356393", name: "Eisner" },
          update: { $setOnInsert: {_id: "project:79792889929982797297972797222"} },
          upsert: true
      })
      

      However Mongo fails with an error:

      	"errmsg" : "exception: Mod on _id not allowed",
      	"code" : 10148,
      	"ok" : 0
      

      I can see why this would be a problem with a $set but not why it would have to fail with a $setOnInsert. The document that is about to be inserted hasn't been inserted yet.

            Assignee:
            Unassigned Unassigned
            Reporter:
            springerw Wilfred Springer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: