我正在搜索一系列商店。商店有一个嵌入式地点集合。我的目标是返回在地理位置附近有商店的商店集合,并且仅返回那些位置在之内的商店。在Mongoose附近使用elemMatch
我可以成功地限制查询只返回商店使用“近”
Store
.where('isActive').equals(true)
.where('outlets.location')
.near({ center: [153.027117, -27.468515], maxDistance: 1000/6378137, spherical: true })
.where('outlets.isActive').equals(true)
.where('products.productType').equals('53433f1f3e02e39addde1954')
.where('products.isActive').equals(true)
.select('name outlets')
.select({'products': {$elemMatch: {'isActive': true, 'productType': '53433f1f3e02e39addde1954'}}})
.select('name outlets')
.execQ()
.then(function (results) {
console.log(results);
})
.fail(function (err) {
console.log(err);
})
.done();
具有在特定位置的出口我的问题是,这家店的文档返回所有的网点,而不仅仅是出口与地理位置相匹配。我尝试过使用elemMatch,像我对产品做过的那样;
。选择({ '网点':{$ elemMatch:{ '位置':{邻近:{中心:[153.027117,-27.468515],maxDistance:六百三十七万八千一百三十七分之一万,球形:真}}}}} )
但是它返回一个空数组。在elemMatch子句中可以使用near操作符吗?我做错了吗?是否有更高效/更快/更好的方式来实现目标?
答案中有些东西不清楚吗?我认为情况已经非常明确地解释了。 –