Exercises: Basic types
These exercises demonstrate how Atlas Search handles the basic data types of boolean, date, number, and ObjectId. Each exercise isolates a specific data type and search operator.
boolean: equalsβ
π Playground link:equals
The documents contain a boolean field, and the query is looking for documents with a value of true
.
Fix the incorrect field name in the query.
Solution
path: "in_stock"
π boolean equals
fixed
boolean: inβ
π Playground link:in
What values are allowed in an in
clause for a boolean
field?
Solution
value: [true, false]
π boolean in
fixed
date: equalsβ
π Playground link:equals
Dates require BSON syntax.
Solution
value: ISODate("2023-11-01T00:00:00.000Z")
π date equals
fixed
date: inβ
π Playground link:in
BSON date syntax is needed.
Solution
value: [ISODate("2024-02-01T00:00:00.000Z"), ISODate("2023-11-01T00:00:00.000Z"), ISODate("2007-12-25T00:00:00.000Z")]
π date in
fixed
date: rangeβ
π Playground link:range
What's the correct field name?
Solution
path: "published_date"
π date range
fixed
number: equalsβ
π Playground link:equals
What's the correct field name?
Solution
path: "price"
π number equals
fixed
number: inβ
π Playground link:in
What numeric value can be used to match one of the documents?
Solution
value: [19.99, 37.5]
π number in
fixed
number: rangeβ
π Playground link:range
There are two issues to fix in this exercise. What's the correct field name? And what's wrong with the one of the range values?
Solution
range: {
path: "price",
gte: 15.00,
lte: 25.00
}
π number range
fixed
ObjectId: equalsβ
π Playground link:equals
ObjectId requires BSON syntax. Copy and paste is your friend here.
Solution
value: ObjectId("5a9427648b0beebeb69589a1")
ObjectId: inβ
π Playground link:in
What value can be placed in the in
array to match the document?
Solution
value: [ObjectId("ba94c7648b0beebeb69589a1"), ObjectId("5a9427648b0beebeb69589a1")]
π ObjectId in
fixed