|
1 | 1 | # Exercises: Basic types |
2 | 2 |
|
3 | | -## boolean |
| 3 | +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. |
| 4 | + |
| 5 | +## boolean: equals |
| 6 | + |
| 7 | +<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c1d80e97570c2714a07e0">🔗 Playground link: `equals`</Playground> |
| 8 | + |
| 9 | +The documents contain a boolean field, and the query is looking for documents with a value of `true`. |
| 10 | +Fix the incorrect field name in the query. |
4 | 11 |
|
5 | | -<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c1d80e97570c2714a07e0">`equals`</Playground> |
6 | 12 | <details> |
7 | 13 | <summary>Solution</summary> |
8 | 14 | <div> |
9 | 15 | ```js |
10 | 16 | path: "in_stock" |
11 | 17 | ``` |
12 | 18 |
|
13 | | - <Playground url="https://search-playground.mongodb.com/tools/code-playground/snapshots/669e6ab1d49ef6fad98118b4">boolean `equals` fixed</Playground> |
| 19 | + 🔗 <Playground url="https://search-playground.mongodb.com/tools/code-playground/snapshots/669e6ab1d49ef6fad98118b4">boolean `equals` fixed</Playground> |
14 | 20 | </div> |
15 | 21 | </details> |
16 | 22 |
|
17 | 23 |
|
18 | | -<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c1e53d0df60f0254e5d2b">`in`</Playground> |
| 24 | +## boolean: in |
| 25 | + |
| 26 | +<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c1e53d0df60f0254e5d2b">🔗 Playground link: `in`</Playground> |
| 27 | + |
| 28 | +What values are allowed in an `in` clause for a `boolean` field? |
| 29 | + |
19 | 30 | <details> |
20 | 31 | <summary>Solution</summary> |
21 | 32 | <div> |
22 | 33 | ```js |
23 | 34 | value: [true, false] |
24 | 35 | ``` |
25 | 36 |
|
26 | | - <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c19c4e97570c2714a07dc">boolean `in` fixed</Playground> |
| 37 | + 🔗 <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c19c4e97570c2714a07dc">boolean `in` fixed</Playground> |
27 | 38 | </div> |
28 | 39 | </details> |
29 | 40 |
|
30 | 41 |
|
31 | | -## date |
32 | | -<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c1b0fe97570c2714a07de">`equals`</Playground> |
| 42 | +## date: equals |
| 43 | + |
| 44 | +<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c1b0fe97570c2714a07de">🔗 Playground link: `equals`</Playground> |
| 45 | + |
| 46 | +Dates require BSON syntax. |
| 47 | + |
33 | 48 | <details> |
34 | 49 | <summary>Solution</summary> |
35 | 50 | <div> |
36 | 51 | ```js |
37 | 52 | value: ISODate("2023-11-01T00:00:00.000Z") |
38 | 53 | ``` |
39 | 54 |
|
40 | | - <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c20a4d0df60f0254e5d2d">date `equals` fixed</Playground> |
| 55 | + 🔗 <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c20a4d0df60f0254e5d2d">date `equals` fixed</Playground> |
41 | 56 | </div> |
42 | 57 | </details> |
43 | 58 |
|
44 | | -<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c1b5fd0df60f0254e5d27">`in`</Playground> |
| 59 | +## date: in |
| 60 | + |
| 61 | +<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c1b5fd0df60f0254e5d27">🔗 Playground link: `in`</Playground> |
| 62 | + |
| 63 | +BSON date syntax is needed. |
| 64 | + |
45 | 65 | <details> |
46 | 66 | <summary>Solution</summary> |
47 | 67 | <div> |
48 | 68 | ```js |
49 | 69 | value: [ISODate("2024-02-01T00:00:00.000Z"), ISODate("2023-11-01T00:00:00.000Z"), ISODate("2007-12-25T00:00:00.000Z")] |
50 | 70 | ``` |
51 | 71 |
|
52 | | - <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c210ee97570c2714a07e2">date `in` fixed</Playground> |
| 72 | + 🔗 <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c210ee97570c2714a07e2">date `in` fixed</Playground> |
53 | 73 | </div> |
54 | 74 | </details> |
55 | 75 |
|
56 | | -<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c21c8d0df60f0254e5d2f">`range`</Playground> |
| 76 | +## date: range |
| 77 | + |
| 78 | +<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c21c8d0df60f0254e5d2f">🔗 Playground link: `range`</Playground> |
| 79 | + |
| 80 | +What's the correct field name? |
| 81 | + |
57 | 82 | <details> |
58 | 83 | <summary>Solution</summary> |
59 | 84 | <div> |
60 | 85 | ```js |
61 | 86 | path: "published_date" |
62 | 87 | ``` |
63 | | - <Playground url="https://search-playground.mongodb.com/tools/code-playground/snapshots/669e6b18d49ef6fad98118b6">date `range` fixed</Playground> |
| 88 | + 🔗 <Playground url="https://search-playground.mongodb.com/tools/code-playground/snapshots/669e6b18d49ef6fad98118b6">date `range` fixed</Playground> |
64 | 89 | </div> |
65 | 90 | </details> |
66 | 91 |
|
67 | 92 |
|
68 | | -## number |
69 | | -<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c25abd0df60f0254e5d35">`equals`</Playground> |
| 93 | +## number: equals |
| 94 | + |
| 95 | +<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c25abd0df60f0254e5d35">🔗 Playground link: `equals`</Playground> |
| 96 | + |
| 97 | +What's the correct field name? |
| 98 | + |
70 | 99 | <details> |
71 | 100 | <summary>Solution</summary> |
72 | 101 | <div> |
73 | 102 | ```js |
74 | 103 | path: "price" |
75 | 104 | ``` |
76 | | - <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c25e2d0df60f0254e5d37">number `equals` fixed</Playground> |
| 105 | + 🔗 <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c25e2d0df60f0254e5d37">number `equals` fixed</Playground> |
77 | 106 | </div> |
78 | 107 | </details> |
79 | 108 |
|
80 | | -<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c252ce97570c2714a07e6">`in`</Playground> |
| 109 | +## number: in |
| 110 | + |
| 111 | +<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c252ce97570c2714a07e6">🔗 Playground link: `in`</Playground> |
| 112 | + |
| 113 | +What numeric value can be used to match one of the documents? |
| 114 | + |
81 | 115 | <details> |
82 | 116 | <summary>Solution</summary> |
83 | 117 | <div> |
84 | 118 | ```js |
85 | 119 | value: [19.99, 37.5] |
86 | 120 | ``` |
87 | | - <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c2569d0df60f0254e5d33">number `in` fixed</Playground> |
| 121 | + 🔗 <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c2569d0df60f0254e5d33">number `in` fixed</Playground> |
88 | 122 | </div> |
89 | 123 | </details> |
90 | 124 |
|
91 | | -<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c2313d0df60f0254e5d31">`range`</Playground> (fix two issues, not just one!) |
| 125 | +## number: range |
| 126 | + |
| 127 | +<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c2313d0df60f0254e5d31">🔗 Playground link: `range`</Playground> |
| 128 | + |
| 129 | +There are *two* issues to fix in this exercises. What's the correct field name? And what's wrong with |
| 130 | +the one of the range values? |
| 131 | + |
92 | 132 | <details> |
93 | 133 | <summary>Solution</summary> |
94 | 134 | <div> |
|
99 | 139 | lte: 25.00 |
100 | 140 | } |
101 | 141 | ``` |
102 | | - <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c22bde97570c2714a07e4">number `range` fixed</Playground> |
| 142 | + 🔗 <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c22bde97570c2714a07e4">number `range` fixed</Playground> |
103 | 143 | </div> |
104 | 144 | </details> |
105 | 145 |
|
106 | | -## ObjectId |
107 | | -<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c265dd0df60f0254e5d39">`equals`</Playground> |
| 146 | +## ObjectId: equals |
| 147 | + |
| 148 | +<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c265dd0df60f0254e5d39">🔗 Playground link: `equals`</Playground> |
| 149 | + |
| 150 | +ObjectId requires BSON syntax. Copy and paste is your friend here. |
| 151 | + |
108 | 152 | <details> |
109 | 153 | <summary>Solution</summary> |
110 | 154 | <div> |
111 | 155 | ```js |
112 | 156 | value: ObjectId("5a9427648b0beebeb69589a1") |
113 | 157 | ``` |
114 | | - <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/67962d77aa132ffc76719f53">ObjectId `equals` fixed</Playground> |
| 158 | + 🔗 <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/67962d77aa132ffc76719f53">ObjectId `equals` fixed</Playground> |
115 | 159 | </div> |
116 | 160 | </details> |
117 | 161 |
|
118 | | -<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c26d5d0df60f0254e5d3b">`in`</Playground> |
| 162 | +## ObjectId: in |
| 163 | + |
| 164 | +<Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c26d5d0df60f0254e5d3b">🔗 Playground link: `in`</Playground> |
| 165 | + |
| 166 | +What value can be placed in the `in` array to match the document? |
| 167 | + |
119 | 168 | <details> |
120 | 169 | <summary>Solution</summary> |
121 | 170 | <div> |
122 | 171 | ```js |
123 | 172 | value: [ObjectId("ba94c7648b0beebeb69589a1"), ObjectId("5a9427648b0beebeb69589a1")] |
124 | 173 | ``` |
125 | | - <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c270cd0df60f0254e5d3d">ObjectId `in` fixed</Playground> |
| 174 | + 🔗 <Playground url="https://search-playground.corp.mongodb.com/tools/code-sandbox/snapshots/679c270cd0df60f0254e5d3d">ObjectId `in` fixed</Playground> |
126 | 175 | </div> |
127 | 176 | </details> |
0 commit comments