$currentDate
Reference group: Update operator families
What it does
Sets current date or a BSON timestamp with the appropriate option.
Syntax
{$currentDate: { field: true }}
Use case
Maintain modification timestamps.
$currentDate: practical example
db.orders.updateOne({ _id: orderId }, { $currentDate: { updatedAt: true } })💡 Explanation
Sets current date or a BSON timestamp with the appropriate option.
When to use it
Maintain modification timestamps.
Key Takeaways
- Sets current date or a BSON timestamp with the appropriate option.
- Typical use: Maintain modification timestamps.