【发布时间】:2018-08-03 01:03:21
【问题描述】:
在 nodejs 中使用聚合时,我变得不确定,对于 find() 查询它正在工作。 python中的相同geoNear查询工作正常,请帮助我
const MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017',(err,client) => {
if(err){
console.log('db connection failed');
} else {
var db = client.db('DB_NAME');
db.collection('COLLECTION',(err, collectionname) => {
if(err){
console.log('unable to connect to collecion');
} else {
collectionname.aggregate([
{
"$geoNear": {
"near":
{"type": "Point","coordinates":[77.102490,28.704059]},
"distanceField": "distancefromcust",
"direction": "direction",
"maxDistance": 1000,
"spherical": "true",
"num":100000
}
},
{"$group":
{
"_id":
{
"operator":"$operator",
"direction":"$direction"
},
"speed":{"$push":"$speed"},
"samples":{"$push":"$samples"},
"distance":{"$push":"$distancefromcust"},
}
}
],(err, item) => {
console.log(item.length);
client.close();
});
}
});
}
});
【问题讨论】: