如何根据 OR 条件查询 mongoose

how to query mongoose based on OR condition

我有一个交易集合,我需要从 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 $and 运算符

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