我有一个具有bankAccounts
属性的文档:
const UsersSchema = new mongoose.Schema({
user_id: {
type: String,
required: true,
},
bankAccounts: [
{
currency: String,
personType: String,
bankName: String,
branchCode: String,
accountNumber: String,
bic: String,
bankCity: String,
accountType: String,
isPrimary: Boolean,
},
]
})
因此,用户可以拥有许多银行帐户。它可以具有currency: USD
和一个currency: EUR
银行帐户。
我正在查询用户,并用该用户拥有的货币数组检索一个用户,因此在此示例中,我的数组将为['USD', 'EUR']
。
我需要对新集合进行新查询,搜索与数组中的一种货币匹配的所有订单:
const orders = await Orders.find({status: "Allocating", currency: oneOfTheArray })
如何在查询中达到OR
条件,迭代数组中的所有货币?
提前谢谢
答案 0 :(得分:0)
尝试一下
const orders = await Orders.find({status: "Allocating", currency: {$in:oneOfTheArray} })