You can try to do a few things if you do not want to process this from the code (I executed the code below directly on the mongo shell):
If you want to use the update of the current currentDate with upsert = true:
db.orders.update(
{"_id":ObjectId()},
{
$currentDate: {
createtime: true
}
},
{ upsert: true }
)
Now it will generate an objectid on the application server instead of a date / time (unless you use the raw command).
Use the new timestamp or date object directly:
db.orders.insert(
"createtime": new Timestamp()
)
, , mondodb, , . , , raw insert.
/ .