mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-01 21:32:35 +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() });
|
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
|
```javascript
|
||||||
db.events.insertOne({
|
db.events.updateOne(
|
||||||
title: 'Sample Event',
|
{ _id: ObjectId('your_document_id') },
|
||||||
eventDate: { $currentDate: { $type: 'date' } },
|
{
|
||||||
});
|
$set: {
|
||||||
|
title: 'Sample Event',
|
||||||
|
eventDate: { $currentDate: { $type: 'date' } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Querying Dates
|
## Querying Dates
|
||||||
|
Reference in New Issue
Block a user