The question is how you determine that "the document" exists? Usually, you'd do this using a unique id. Now MongoDB's ObjectId
comes to the rescue because it contains a timestamp already. This can also be used in queries.
Instead of using an integer field User_ID
, you might want to consider calling the field _id
and use the ObjectId
data type so you get that functionality for free.
> db.test.insert({"foo" : "test"});
{ "_id" : ObjectId("51cb763e58bb4077aea65b3d"), "foo" : "test" }
> var foo = db.test.findOne();
> foo._id.getTimestamp();
ISODate("2013-06-26T23:16:14Z")