我试图从我的userId
中得到结果,以便type != 4
和userType != 1
我试过了:
const transaction = {
userId: userId,
$and: [{ type: { $ne: 4 } }, { userType: { $ne: 1 } }]
};
await.Transactions.find(transaction)
但这给了我空集。
以下是我的数据库数据片段
id: 5ed8dfb1b6c73a69b0adca7d
amount: 150
userId: 5ed5c7fdc25ee07e41a502af
type: 4
userType: 1
recipientId: 5ed8d3a36b34b55f66f62fcd
status:"succeeded"
_id: 5ed987747833b724d9f31829
amount: 1000
userId: 5ed8d3a36b34b55f66f62fcd
type: 4
userType: 2
ChargeId: "tr_1GqSjvKYps1wFgvm0thxzh0p"
ChargeObject: "transfer"
status: "pending"
__v: 0
_id: 5ed987747833b724d9f31841
amount: 1000
userId: 5ed8d3a36b34b55f66f62fcd
type: 3
userType: 1
ChargeId: "ch_1GqSjvKYps1wFgvm0thxzh0p"
ChargeObject: "charge"
status: "pending"
__v: 0
根据您的标准,它应该是这样的:
{ $and:[ {userId: userId},{ type: { $ne: 4 } }, { userType: { $ne: 1 } } ] }
条件是type != 4
和userType != 1
,如果要排除同时满足这两个条件的文档,则此语句对于要匹配的文档将成立:
not(and(type != 4, userType != 1 ))
这似乎是一些过分的否定,以上在逻辑上等同于:
or(type = 4, userType = 1)
在 MQL 中:
{userId: userId, $or:[ {type: 4}, {userType: 1} ]}