0
0
MongoDBquery~10 mins

Geospatial queries basics 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 near a point using $near.

MongoDB
db.places.find({ location: { $near: { $geometry: { type: "Point", coordinates: [1] } } } })
Drag options to blanks, or click blank then click option'
A40, -70
B[40, -70]
C{40, -70}
D["40", "-70"]
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of numbers for coordinates.
Using curly braces instead of square brackets.
Not wrapping coordinates in an array.
2fill in blank
medium

Complete the code to find documents within a polygon using $geoWithin.

MongoDB
db.parks.find({ area: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [1] } } } })
Drag options to blanks, or click blank then click option'
A{[0,0],[3,6],[6,1],[0,0]}
B[[0,0],[3,6],[6,1],[0,0]]
C[[[0,0],[3,6],[6,1],[0,0]]]
D[0,0,3,6,6,1,0,0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using single array instead of nested arrays for polygon coordinates.
Not closing the polygon by repeating the first point at the end.
Using curly braces instead of square brackets.
3fill in blank
hard

Fix the error in the query to find documents near a point with max distance.

MongoDB
db.stores.find({ location: { $near: { $geometry: { type: "Point", coordinates: [ -73.97, 40.77 ] }, $maxDistance: [1] } } })
Drag options to blanks, or click blank then click option'
A1000
B"1000"
C[1000]
D{1000}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number for $maxDistance.
Using an array or object instead of a number.
Omitting $maxDistance or placing it incorrectly.
4fill in blank
hard

Fill both blanks to find documents within a circle using $geoWithin and $centerSphere.

MongoDB
db.locations.find({ position: { $geoWithin: { $centerSphere: [ [1], [2] ] } } })
Drag options to blanks, or click blank then click option'
A[ -73.97, 40.77 ]
B40.77
C0.01
D[ -73.97, 40.77, 0.01 ]
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the radius inside the coordinates array.
Using latitude before longitude in coordinates.
Using degrees instead of radians for radius.
5fill in blank
hard

Fill all three blanks to find documents near a point with min and max distance.

MongoDB
db.places.find({ location: { $near: { $geometry: { type: "Point", coordinates: [1] }, $minDistance: [2], $maxDistance: [3] } } })
Drag options to blanks, or click blank then click option'
A[ -73.97, 40.77 ]
B500
C2000
D[ 40.77, -73.97 ]
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping latitude and longitude in coordinates.
Using strings instead of numbers for distances.
Omitting $minDistance or $maxDistance.