[英]mongoose query to find based on multiple not equals
我正在尝试从我的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} ]}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.