|
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.
|