因此,假设以下数据作为MongoDB文档:
{
"_id" : NumberInt(8),
"shopId" : "1",
"name" : "SomeProduct",
"price" : "0.00",
"image" : "someUrl",
"description" : null,
"location" : {
"type" : "Point",
"coordinates" : [
-0.7572565,
52.0726237
]
}
}
当我运行以下聚合时:
collection.aggregate(
{
$geoNear: {
near: { type: 'Point', coordinates: [position.long, position.lat] },
maxDistance: 5 * 1609.34,
distanceField: 'dist.calculated',
key: "location",
query: { name: /foo/ },
spherical: true,
},
},
).toArray())
我仍然找回与SomeProduct相关的文档,但是显然它应该与要求名称具有“ Foo”的查询匹配?
此外,我似乎没有将距离字段包含在结果中吗?我对MongoDB相当陌生,因此,非常感谢您的帮助。