javascript - Moongose .geoNear aggregation, add basic query options -
i using mongoose
library node.js
, , geonear
aggregation function.
here piece of code, works charm :
user.geonear({ type: "point", coordinates: [geo.lon, geo.lat] }, { spherical: true, maxdistance: 50, }, function(err, results, stats) { if (err) { // handle err } }
now add basic query options, such excluding documents mongodb $nin
option. example, search users around given position (as did in example) constraint of not matching given ids
. how possible add kind of options query ?
you can with aggregation framework. try:
db.collection.aggregate( [ { '$geonear': { 'near': { 'type': 'point', 'coordinates': [ -77.395410 , 38.967995 ] }, 'spherical': true, 'distancefield': 'dist', 'maxdistance': 5000 } }, { $match:{_id:{$nin: [objectid("5716163704ca42c7b579c7e3")]}} } ]);
query above search documents in 5000 meters radius , exclude document given _id.
Comments
Post a Comment