Skip to main content

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 equals fixed

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