0
0
MongoDBquery~10 mins

TTL indexes for auto-expiry 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 TTL index on the 'createdAt' field that expires documents after 3600 seconds.

MongoDB
db.collection.createIndex({ createdAt: 1 }, { expireAfterSeconds: [1] })
Drag options to blanks, or click blank then click option'
A3600
B60
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or negative numbers which disable TTL expiration.
Confusing minutes with seconds.
2fill in blank
medium

Complete the code to create a TTL index on the 'lastModified' field that expires documents after 86400 seconds (1 day).

MongoDB
db.collection.createIndex({ [1]: 1 }, { expireAfterSeconds: 86400 })
Drag options to blanks, or click blank then click option'
AcreatedAt
BlastModified
Ctimestamp
DexpireAt
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong field name for the TTL index.
Confusing the field with other date fields.
3fill in blank
hard

Fix the error in the TTL index creation code by filling the blank with the correct option.

MongoDB
db.collection.createIndex({ expireAt: 1 }, { [1]: 3600 })
Drag options to blanks, or click blank then click option'
AexpireAfter
BexpireAfterMinutes
CexpireAfterSeconds
DexpireSeconds
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect option names like 'expireAfterMinutes' or 'expireSeconds'.
Misspelling the option name.
4fill in blank
hard

Fill both blanks to create a TTL index on 'timestamp' field that expires documents after 7200 seconds (2 hours).

MongoDB
db.collection.createIndex({ [1]: [2] }, { expireAfterSeconds: 7200 })
Drag options to blanks, or click blank then click option'
Atimestamp
B1
C-1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using -1 or 0 as index direction which is invalid here.
Using wrong field names.
5fill in blank
hard

Fill all three blanks to create a TTL index on 'expireAt' field with ascending order and expiration after 1800 seconds (30 minutes).

MongoDB
db.collection.createIndex({ [1]: [2] }, { [3]: 1800 })
Drag options to blanks, or click blank then click option'
AexpireAt
B1
CexpireAfterSeconds
Dtimestamp
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong field names or index directions.
Using incorrect option names for expiration.