猫鼬查询基于多个不等于查找

时间:2020-06-05 01:25:15

标签: node.js mongodb mongoose

我正在尝试从userIdtype != 4的{​​{1}}获取结果

我尝试过:

userType != 1

但这给了我空缺。

下面是我的数据库数据的一个片段

const transaction = {
    userId: userId,
    $and: [{ type: { $ne: 4 } }, { userType: { $ne: 1 } }]
  };
await.Transactions.find(transaction)

2 个答案:

答案 0 :(得分:0)

根据您的条件,应该像这样:

{ $and:[ {userId: userId},{ type: { $ne: 4 } }, { userType: { $ne: 1 } } ] }

答案 1 :(得分:0)

条件为type != 4userType != 1,如果要排除两个都为真的文档,则此语句对于要匹配的文档为真:

not(and(type != 4, userType != 1 ))

这似乎有点过分否定,以上在逻辑上等同于:

or(type = 4, userType = 1)

在MQL中:

{userId: userId, $or:[ {type: 4}, {userType: 1} ]}