gpt4 book ai didi

mongodb - 如何根据OR条件查询mongoose

转载 作者:行者123 更新时间:2023-12-04 09:51:57 27 4
gpt4 key购买 nike

我有一个交易集合,我需要从 Mongoose 查询这个

    _id: 5ecba0d446d0354084ad0b89
amount: 3
userId: 5ec3285cc7762963c88db765
type: 4
userType: 1
recipientId: 5ec328f2c7762963c88db768
status: "succeeded"
createdAt: 2020-05-25T10:41:24.449+00:00
updatedAt: 2020-05-25T10:41:24.449+00:00
__v: 0


_id: 5ecba0d446d0354084ad0b92
amount: 4
userId: 5ec3285cc7762963c88db888
type: 4
userType: 1
recipientId: 5ec3285cc7762963c88db765
status: "succeeded"
createdAt: 2020-05-25T10:41:24.449+00:00
updatedAt: 2020-05-25T10:41:24.449+00:00
__v: 0


_id: 5ecba0d446d0354084ad0b97
amount: 8
userId: 5ec3285cc7762963c88db332
type: 4
userType: 1
recipientId: 5ec328f2c7762963c88db589
status: "succeeded"
createdAt: 2020-05-25T10:41:24.449+00:00
updatedAt: 2020-05-25T10:41:24.449+00:00
__v: 0

如何查询,以便我可以根据以下条件获取交易
userId = 5ec3285cc7762963c88db765 or recipientId = 5ec3285cc7762963c88db765
and type = 4
and userType = 1

最佳答案

使用 $or$and运营商

model.find({
$or: [
{ userId: 5ec3285cc7762963c88db765 },
{ recipientId: 5ec3285cc7762963c88db765 }
],
$and: [ { type: 4 }, { userType: 1 } ]
});

关于mongodb - 如何根据OR条件查询mongoose,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62001369/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com