MongoDB: insert on duplicate key update
I asked this question on mongodb user group, the answer was that it is not possible and this is an open issue.
From
I would call it "MyCollection" instead of "mytable".You can do the following:
db.mycollection.update( { MyUniqueKey: "?" }, { $set: {"y": "?"}, $setOnInsert: { MyUniqueKey: "?", "x": "?", }, { upsert: true })
Basically the $set runs always, except when document does not exist. Then $setOnInsert will run.