0

I am trying featherjs for the first time. And stuck on how to use $geoNear to fliter by geo location. I am not using mongoose, only feathers-mongodb

4

1 回答 1

0

This can be accomplished by accessing the MongoDB collection directly through app.service('myservice').Model and running the $geoNear aggregate:

const results = await app.service('myservice').Model.aggregate([ {
    $geoNear: {
      includeLocs: "location",
      distanceField: "distance",
      near: {type: 'Point', coordinates: [lng, lat]},
      maxDistance: 1000,
      spherical: true
    }
]);

You can set this as context.result in a hook or use it anywhere else you need it.

于 2019-02-27T04:09:50.467 回答