I have a Mongo collection looking like this:
{
"id": _id_,
"doc": _some data_,
"timestamp": _timestamp_
}
I would like to insert a new entry if there is none with the same id, or update the existing entry if it exists, but only update it if the new document has a timestamp greater than the existing entry.
What is the best way of achieving this in MongoDB? Can I do this in a single query?