Complete the code to create a new Date object representing the current date and time.
const currentDate = new [1]();The Date object in MongoDB JavaScript represents date and time. Using new Date() creates the current date and time.
Complete the code to insert a document with a field 'createdAt' set to the current date and time.
db.collection.insertOne({ createdAt: [1] });Date() without 'new' which returns a string, not a Date object.Timestamp() which is a different type.To store the current date and time in a document, use new Date(). This creates a Date object representing now.
Fix the error in the query to find documents with a 'createdAt' date greater than January 1, 2023.
db.collection.find({ createdAt: { $gt: [1] } })The $gt operator compares dates. You must provide a Date object. new Date('2023-01-01') creates a valid Date object for comparison.
Fill both blanks to create a query that finds documents with a 'lastModified' timestamp less than or equal to the current time.
db.collection.find({ lastModified: { [1]: [2] } })$lt instead of $lte changes the condition.Timestamp() without 'new' or parameters is incorrect.The operator $lte means 'less than or equal to'. Using new Date() gives the current date and time for comparison.
Fill all three blanks to create an update that sets the 'updatedAt' field to the current date and increments a 'version' field by 1.
db.collection.updateOne({ _id: id }, { [1]: { updatedAt: [2] }, [3]: { version: 1 } })$currentDate instead of $set with new Date().$set updates fields to specific values, here setting updatedAt to the current date with new Date(). $inc increments the version field by 1.