0
0
MongoDBquery~10 mins

ObjectId and how it is generated in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new ObjectId in MongoDB.

MongoDB
const id = new [1]();
Drag options to blanks, or click blank then click option'
AMongoId
BObject
CIdObject
DObjectId
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Object' instead of 'ObjectId' will not create a MongoDB ID.
Misspelling the constructor name causes errors.
2fill in blank
medium

Complete the code to extract the timestamp from an ObjectId.

MongoDB
const timestamp = id.[1]();
Drag options to blanks, or click blank then click option'
AtoDate
Btimestamp
CgetTimestamp
DgetTime
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'toDate' which is not a valid method.
Confusing 'timestamp' property with a method.
3fill in blank
hard

Fix the error in the code to create an ObjectId from a hex string.

MongoDB
const id = new ObjectId([1]);
Drag options to blanks, or click blank then click option'
A"1234567890abcdef12345678"
B'1234567890abcdef12345678'
CObjectId("1234567890abcdef12345678")
D1234567890abcdef12345678
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the hex string without quotes causes a ReferenceError.
Using ObjectId() inside new ObjectId() is incorrect.
4fill in blank
hard

Fill both blanks to create an ObjectId and get its timestamp as a Date.

MongoDB
const id = new [1]();
const time = id.[2]();
Drag options to blanks, or click blank then click option'
AObjectId
BtoDate
CgetTimestamp
DIdObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong constructor names.
Using non-existent methods like toDate.
5fill in blank
hard

Fill all three blanks to create an ObjectId from a hex string, convert it to a Date, and print it.

MongoDB
const id = new [1]([2]);
const date = id.[3]();
console.log(date);
Drag options to blanks, or click blank then click option'
AObjectId
B"507f1f77bcf86cd799439011"
CtoDate
DgetTimestamp
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the hex string without quotes.
Using 'toDate' which is not a valid method.
Misspelling 'ObjectId' or 'getTimestamp'.