How to set the default value for mongodb field

I have a problem. I want to automatically give a current time when I insert a piece of data for the first time, because I need to use upsert to ensure efficiency, so I can"t process it one by one with find. How can I set a default value for this? Checked the mongodb does not seem to support, ask the great god to solve the doubt.

Mar.28,2021

db.<coll>.update({}, {$set: {}, $setOnInsert: {date: new Date()}}, {upsert: true});

plus $setOnInsert indicates that this field is only available when inserted. Unlike a relational database, this time comes from your application, not the default value added to the database.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b41520-415c5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b41520-415c5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?