$center

Specifies a circle using legacy coordinate pairs for $geoWithin queries, defining a circle for geospatial query on a flat, Euclidean plane.

Syntax

{ $geoWithin: { $center: [ [<x>, <y>], <radius> ] } }

Parameters

xnumberrequired

The x-coordinate of the circle's center point

ynumberrequired

The y-coordinate of the circle's center point

radiusnumberrequired

The radius of the circle in the same units as the coordinates

Examples

Find stores within circular area

Find stores within a 50-degree radius using flat plane calculations

Query:

db.stores.find({ location: { $geoWithin: { $center: [[-112.7858, -29.1866], 50] } } })

Output:

Stores within 50-degree radius using Euclidean plane calculations

Circular area query with projection

Find stores within circular area and return specific fields

Query:

db.stores.find({ location: { $geoWithin: { $center: [[-82.5543, -65.105], 5] } } }, { name: 1, location: 1 })

Output:

Limited projection of stores within 5-degree radius circle

Related