0
0
MongoDBquery~10 mins

Partial indexes with filter 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 partial index on the 'status' field where status is 'active'.

MongoDB
db.users.createIndex({ status: 1 }, { partialFilterExpression: { status: [1] } })
Drag options to blanks, or click blank then click option'
A"active"
Bactive
C1
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around string values in the filter expression.
Using a boolean or number instead of a string.
2fill in blank
medium

Complete the code to create a partial index on the 'age' field only for documents where age is greater than 18.

MongoDB
db.people.createIndex({ age: 1 }, { partialFilterExpression: { age: { [1]: 18 } } })
Drag options to blanks, or click blank then click option'
A$lt
B$eq
C$gt
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $lt which means 'less than' instead of 'greater than'.
Using $eq which means 'equal to' instead of 'greater than'.
3fill in blank
hard

Fix the error in the partial index creation by completing the filter expression correctly.

MongoDB
db.orders.createIndex({ total: 1 }, { partialFilterExpression: { total: { [1]: 100 } } })
Drag options to blanks, or click blank then click option'
A$gte
Bgte
C$greater
D=>
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the dollar sign in the operator.
Using invalid operators like 'gte' or '=>'.
4fill in blank
hard

Fill both blanks to create a partial index on 'category' where category is either 'books' or 'magazines'.

MongoDB
db.library.createIndex({ category: 1 }, { partialFilterExpression: { category: { [1]: [[2]] } } })
Drag options to blanks, or click blank then click option'
A$in
B"books", "magazines"
C"books", "movies"
D$nin
Attempts:
3 left
💡 Hint
Common Mistakes
Using $nin which means 'not in' instead of $in.
Including wrong values like 'movies' instead of 'magazines'.
5fill in blank
hard

Fill both blanks to create a partial index on 'score' where score is between 50 and 100 inclusive.

MongoDB
db.scores.createIndex({ score: 1 }, { partialFilterExpression: { score: { [1]: 50, [2]: 100 } } })
Drag options to blanks, or click blank then click option'
A$gte
B$lte
C$gt
D$lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using $gt or $lt which exclude boundary values.
Mixing up $gte and $lte operators.