location field as GeoJSON points, what will be the output of this query?db.places.find({ location: { $geoWithin: { $centerSphere: [[-73.97, 40.77], 0.0001] } } })The query finds documents within a circle centered at longitude -73.97, latitude 40.77 with radius 0.0001 radians.
The $centerSphere operator defines a circle on the Earth's surface using radians. Radius 0.0001 radians corresponds to about 637 meters (0.0001 * Earth's radius β 6371 km). So the query returns documents whose location is within that circle.
2dsphere index is correct?The 2dsphere index supports GeoJSON objects and performs calculations assuming a spherical Earth, which is important for accurate geospatial queries.
db.places.find({ location: { $near: { $geometry: { type: "Point", coordinates: [-73.97, 40.77] }, $maxDistance: 1000 } } })In MongoDB geospatial queries, the distance option must be $maxDistance with a dollar sign. Option A uses maxDistance without the dollar sign, causing a syntax error.
restaurants with a location field storing GeoJSON points. Which index will optimize queries that find restaurants near a given point?The 2dsphere index supports GeoJSON points and spherical calculations, which are needed for near queries on Earth coordinates. The 2d index is for flat coordinate pairs and does not support GeoJSON.
parks with a location field indexed as 2dsphere:db.parks.find({ location: { $geoWithin: { $box: [[-74, 40], [-73, 41]] } } })But it returns no documents, even though you know some parks are inside that box. What is the most likely reason?
The $box operator works only with legacy 2d indexes and flat coordinate pairs. It is not supported with 2dsphere indexes, which require GeoJSON geometry operators like $geometry or $centerSphere.