Considering a simple mongo document structure:
{ _id, firstTime, lastTime }
The client needs to insert a document with a known ID, or update an existing docu
I ran into the exact same problem and there was no simple solution for <2.4 however since 2.4 the $setOnInsert operator let's you do exactly that.
db.collection.update( , { $setOnInsert: { "firstTime": } }, { upsert: true } )
See the 2.4 release notes of setOnInsert for more info.