MongoDB provides a way to update a date field by the system on update operations: https://docs.mongodb.com/manual/reference/operator/update/currentDate/. Is there any equiva
The $currentDate is an update operator which populates date field with current date through update operation.
To auto populate date field while insertion of new MongoDB document,please try executing following code snippet
var current_date=new Date();
db.collection.insert({datefield:current_date})
In above code snippet the statement
new Date()
creates a new JavaScript Date object which consists of a year, a month, a day, an hour, a minute, a second, and milliseconds