Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

current date in mongodb

1. Date() returns the current date as a string in mongosh.
2. new Date() returns the current date as a Date object

db.products.updateOne(
   { _id: 1 },
   {
     $set: { item: "apple" },
     $setOnInsert: { dateAdded: new Date() }
   },
   { upsert: true }
)
Source by www.mongodb.com #
 
PREVIOUS NEXT
Tagged: #current #date #mongodb
ADD COMMENT
Topic
Name
3+8 =