‘Date.now()’ function is used to set the field with current timestamp.
Example
db.audit.insert({"type" : "login", "client" : "mobile", "userId" : 123, "createdTimestamp": Date.now()})
Find the below snippet.
> db.audit.insert({"type" : "login", "client" : "mobile", "userId" : 123, "createdTimestamp": Date.now()}) WriteResult({ "nInserted" : 1 }) > > db.audit.find().pretty() { "_id" : ObjectId("60bb0156baf44d88348459c4"), "type" : "login", "client" : "mobile", "userId" : 123, "createdTimestamp" : 1622868310979 }
No comments:
Post a Comment