0
0
MongoDBquery~10 mins

$nin for not in set 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 find documents where the field 'status' is not in the list ['A', 'D'].

MongoDB
db.collection.find({ status: { [1]: ['A', 'D'] } })
Drag options to blanks, or click blank then click option'
A$in
B$nin
C$eq
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $in instead of $nin will select documents with values inside the list, not outside.
Using $ne only checks for not equal to a single value, not a list.
2fill in blank
medium

Complete the code to find documents where 'category' is not in the array ['electronics', 'furniture'].

MongoDB
db.products.find({ category: { [1]: ['electronics', 'furniture'] } })
Drag options to blanks, or click blank then click option'
A$nin
B$eq
C$in
D$ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using $in will include documents with those categories, not exclude them.
Using $ne only works for single values, not arrays.
3fill in blank
hard

Fix the error in the query to find documents where 'type' is not in ['admin', 'guest'].

MongoDB
db.users.find({ type: { [1]: ['admin', 'guest'] } })
Drag options to blanks, or click blank then click option'
A$nin
B$in
C$ne
D$not
Attempts:
3 left
💡 Hint
Common Mistakes
Using $in includes the values instead of excluding them.
Using $ne only excludes one value, not multiple.
4fill in blank
hard

Fill both blanks to find documents where 'color' is not in ['red', 'blue'] and 'size' is not in ['small', 'medium'].

MongoDB
db.items.find({ color: { [1]: ['red', 'blue'] }, size: { [2]: ['small', 'medium'] } })
Drag options to blanks, or click blank then click option'
A$nin
B$in
C$ne
D$eq
Attempts:
3 left
💡 Hint
Common Mistakes
Using $in will include the values instead of excluding them.
Mixing $ne with $nin causes inconsistent filtering.
5fill in blank
hard

Fill all three blanks to find documents where 'status' is not in ['active', 'pending'], 'role' is not in ['admin', 'user'], and 'age' is not in [20, 30].

MongoDB
db.members.find({ status: { [1]: ['active', 'pending'] }, role: { [2]: ['admin', 'user'] }, age: { [3]: [20, 30] } })
Drag options to blanks, or click blank then click option'
A$in
B$nin
C$ne
D$eq
Attempts:
3 left
💡 Hint
Common Mistakes
Using $in includes the values instead of excluding them.
Using $ne only excludes single values, not lists.