0
0
MongoDBquery~20 mins

BSON data types overview in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
BSON Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this BSON document query?
Given a MongoDB collection with documents containing a field value of type Int32, what will be the output of this query?

db.collection.find({ value: { $type: 16 } })

Note: $type: 16 filters documents where value is of BSON type Int32.
MongoDB
db.collection.find({ value: { $type: 16 } })
AReturns documents where 'value' is a 32-bit integer (Int32).
BReturns documents where 'value' is a 64-bit integer (Int64).
CReturns documents where 'value' is a double (floating point).
DReturns documents where 'value' is a string.
Attempts:
2 left
💡 Hint
Check the BSON type number for Int32 in MongoDB documentation.
🧠 Conceptual
intermediate
1:30remaining
Which BSON data type is used to store date and time?
In BSON, which data type is used to store date and time values?
ADate
BTimestamp
CString
DObjectId
Attempts:
2 left
💡 Hint
Think about the type that stores calendar dates and times.
📝 Syntax
advanced
1:30remaining
Identify the BSON type code for a 64-bit integer
Which BSON type number corresponds to a 64-bit integer (Int64) in MongoDB?
A16
B18
C1
D2
Attempts:
2 left
💡 Hint
Int32 is 16, double is 1, string is 2.
🔧 Debug
advanced
2:00remaining
Why does this query return no results?
A user runs this query to find documents with a field score of type double:

db.collection.find({ score: { $type: 1 } })

But no documents are returned, even though some documents have score as a floating-point number. What is the most likely reason?
AThe query syntax is incorrect; $type expects a string, not a number.
BThe collection is empty.
CThe <code>score</code> field is stored as Int32, not double.
DThe <code>score</code> field is stored as string, not double.
Attempts:
2 left
💡 Hint
Check the actual BSON type of the score field in documents.
optimization
expert
2:30remaining
Optimizing queries filtering by BSON type
You want to optimize a MongoDB query that filters documents by the BSON type of a field data. Which approach is the most efficient for large collections?
AUse <code>{ data: { $exists: true } }</code> and then check type in application.
BUse <code>{ $where: function() { return typeof this.data === 'number'; } }</code>.
CUse <code>{ data: { $type: <type_number> } }</code> with an index on <code>data</code>.
DScan all documents and filter in application code after fetching.
Attempts:
2 left
💡 Hint
Indexes help queries run faster when used properly.