MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Ambiguità su $geoNear nella query aggregata

Puoi utilizzare $expr

Location.aggregate([
  { "$geoNear": {
    "spherical": true,
    "near": { "type": "Point", "coordinates": [ user.location.coordinates[0], user.location.coordinates[1] ] },
    "distanceField": "dist.calculated"
  }},
  { "$match": { "$expr": { "$lte": ["$distanceField", "$distance"] }}}
])