From 7f6a42a0c585b0c8e4e0a0e3d134a5d2f0db24cb Mon Sep 17 00:00:00 2001 From: Abdelrhman Kamal Date: Wed, 25 Oct 2023 11:47:15 +0300 Subject: [PATCH] Clarify Usage of MongoDB's $currentDate operator (#4630) * Fix gtx-trans close sidepanel * reset the package-lock.json file * Fix: mongoDB date type --- .../mongodb/content/101-datatypes/110-date.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/data/roadmaps/mongodb/content/101-datatypes/110-date.md b/src/data/roadmaps/mongodb/content/101-datatypes/110-date.md index ee2a3a7d9..54524b1c9 100644 --- a/src/data/roadmaps/mongodb/content/101-datatypes/110-date.md +++ b/src/data/roadmaps/mongodb/content/101-datatypes/110-date.md @@ -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