我被这个查询困住了,甚至不确定我应该通过谷歌搜索什么来找到解决方案,在这个查询中,我正在寻找附加到特定帐户的客户,但如果客户的状态为“避免”或“阻止”,则查询应返回空结果。如果没有“$nin”表达式,此查询工作正常,但在输入 $nin 后,出现错误:
{ $lookup : {
from : 'client' ,
let : { id: '$client_id' },
pipeline : [{
$match : {
$expr : {
$and : [
{ $eq : ['$client_id', this.ObjectID(meta.query._id)] },
{ $eq : ['$account_id', '$$id'] },
{ $nin : ['$status' , 'deny' , 'blocked']}
]
}
}
UnhandledPromiseRejectionWarning: MongoError: Unrecognized expression '$nin'
Run Code Online (Sandbox Code Playgroud)
小智 14
感谢 bur\xc3\xa6quete,解决了这个问题:
\n\n{ $lookup : {\n from : \'client\' ,\n let : { id: \'$client_id\' },\n pipeline : [{\n $match : {\n $expr : {\n $and : [\n { $eq : [\'$client_id\', this.ObjectID(meta.query._id)] },\n { $eq : [\'$account_id\', \'$$id\'] },\n { "$not": { "$in": ["$status", ["deny","blocked"]] }}\n ]\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
4888 次 |
| 最近记录: |