obj = {
date: 137097408891,
id: '1234',
value: 'value'
}
What I want to do it apply the value field to the object with the id, only if the date is newer then the current one saved. If no document with that ID is saved, just save this one.
I'm using node-mongodb-native. Is there a way to do this without first getting the document checking the date and saving it again?
Thanks
Given object o
db.collection.update( { id:o.id, date: { $lt:o.date } }, {$set : { o }}, {upsert:true} );
This is assuming there is a unique index on id.