我試著用$match過濾器和$near過濾器來過濾集合(以了解有多少專案符合查詢)
。下面是我的函式
this.usersModel.aggregate( [
{
$match: {
practices: 'practice1',
status: 'new',
},
$geoNear: {
near: { type: 'Point', coordinates: ['43.48', '5.34'] },
key: 'address',
},
},
{
$facet: {
metadata: [
{
$group: {
_id: null,
total: { $sum: 1 },
},
},
],
data: [{ $sort: sort }, { $skip: skip }, { $limit: limit }]。
},
},
]);
對于資訊'Addresses'是一個帶有索引的地理空間欄位。
當我用mongoose運行這個函式時,我得到了這樣的錯誤
。Arguments must be aggregate pipeline operators
uj5u.com熱心網友回復:
這是你的問題:
{
$match: {
practices: 'practice1',
status: 'new',
},
$geoNear: {
near: { type: 'Point', coordinates: ['43.48', '5.34'] },
key: 'address',
},
},
我不確定這是不是一個錯誤,但你基本上是把兩個管道運算子合并成一個,這就是為什么分析器不能理解發生了什么。
把它改成:
{
$geoNear: {
near: { type: 'Point', coordinates: ['43.48', '5.34'] },
key: 'address',
},
},
{
$match: {
practices: 'practice1',
status: 'new',
}
},
... rest of pipeline
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/333046.html
標籤:
下一篇:使用CHARINDEX查找字串
