I have a mongo database, and I want to use the following versioning system: when a user adds a document, I store the time stamp of that insertion. When a second user gets the document, he gets that time stamp of the latest document inserted. He is only able to add his own document if the time stamp he has stored is the the latest time stamp of all the documents currently stored. This ensures that he does not have a stale copy when he makes an insertion.
My issue is that I can't find any atomic operation for "add if". Sure, there is findAndModify, and the query parameter of the update function, but I don't want to update if the query returns true - I want to add an entirely new document. Is there any support for this functionality?