ololo
ololo

Reputation: 2006

What is the default unit for maxDistance in Mongodb query

It's not really clear what should be the unit for $maxDistance in mongodb geospatial queries.

Here is my code

 return await User.find({
                location: {
                    $near: {
                        $maxDistance: maxDistance, //Is this in Meters or KM?
                        $geometry: {
                            type: "Point",
                            coordinates: [longitude, latitude]
                        }
                    }
                },

I would love my $maxDistance to always be in Meters. What should I do? Thanks.

Upvotes: 0

Views: 269

Answers (1)

RickN
RickN

Reputation: 13500

The search operator $near uses meters in $maxDistance and minDistance.

   $maxDistance: <distance in meters>,
   $minDistance: <distance in meters>

Upvotes: 1

Related Questions