0
0
MongoDBquery~10 mins

Attribute pattern for variable fields 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 name starts with 'user_'.

MongoDB
db.collection.find({ [1]: { $exists: true } })
Drag options to blanks, or click blank then click option'
A"user_*"
B"user_"
C/^user_/
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes without regex syntax.
Using wildcard characters like '*' inside quotes incorrectly.
2fill in blank
medium

Complete the code to find documents where the field name starts with 'data_'.

MongoDB
db.collection.find({ [1]: { $exists: true } })
Drag options to blanks, or click blank then click option'
A"data_.*"
B/^data_/
C"data_*"
D"data_"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wildcard '*' inside quotes without regex.
Using string patterns like 'data_.*' incorrectly.
3fill in blank
hard

Fix the error in the query to find documents with any field starting with 'attr_'.

MongoDB
db.collection.find({ [1]: { $exists: true } })
Drag options to blanks, or click blank then click option'
A/^attr_/
B"attr_.*"
C"attr_"
D"attr_*"
Attempts:
3 left
💡 Hint
Common Mistakes
Using string patterns without regex.
Using incorrect regex syntax.
4fill in blank
hard

Fill both blanks to create a query that finds documents where any field starting with 'meta_' has the value 'active'.

MongoDB
db.collection.find({ [1]: [2] })
Drag options to blanks, or click blank then click option'
A/^meta_/
B"active"
Ctrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using string instead of regex for field names.
Using boolean true instead of string 'active'.
5fill in blank
hard

Fill all three blanks to create an aggregation pipeline that filters documents where the 'info_score' field has a numeric value greater than 10, and projects that field.

MongoDB
db.collection.aggregate([{ $match: { [1]: { $gt: [2] } } }, { $project: { [3]: 1 } }])
Drag options to blanks, or click blank then click option'
A"info_score"
B10
D"info_value"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect field names.
Using string '10' instead of number 10.