1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-09-01 13:22:38 +02:00

Clarify Usage of MongoDB's $currentDate operator (#4630)

* Fix gtx-trans close sidepanel

* reset the package-lock.json file

* Fix: mongoDB date type
This commit is contained in:
Abdelrhman Kamal
2023-10-25 11:47:15 +03:00
committed by GitHub
parent cc258b7612
commit 7f6a42a0c5

View File

@@ -20,13 +20,18 @@ When inserting a document with a Date field, you can store the date value as fol
db.events.insertOne({ title: 'Sample Event', eventDate: new Date() });
```
You can also specifically store the current date and time using MongoDB's `$currentDate` operator:
You can also store the current date and time using MongoDB's `$currentDate` operator when updating a document:
```javascript
db.events.insertOne({
title: 'Sample Event',
eventDate: { $currentDate: { $type: 'date' } },
});
db.events.updateOne(
{ _id: ObjectId('your_document_id') },
{
$set: {
title: 'Sample Event',
eventDate: { $currentDate: { $type: 'date' } }
}
}
);
```
## Querying Dates