Alex V
Alex V

Reputation: 1155

Geospatial filtering of documents with locations within a given radius from given point with LoopbackJS

There is a requirement to do a query for documents which are within a certain radius from a given point. If you use MongoDB as a database, you can do the following:

What would be the proper way to achieve the same using Loopback's Geopoint, near and lt?

Crossposted here as well: https://groups.google.com/forum/#!topic/loopbackjs/ncG7NdJ-eEQ

Upvotes: 1

Views: 432

Answers (1)

xangy
xangy

Reputation: 1205

Location.find({where: {loc: {near: [-110.111111, 30.333333], maxDistance: 10}}})

This will do where 'Location' is your model name. 'loc' is your location field. 'near' specifies center coordinates. and 'maxDistance' specifies area to cover.

Also, this is for 2d indexes.

Upvotes: 1

Related Questions