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:
@@ -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
|
||||
|
Reference in New Issue
Block a user