[英]Using mongoose to find a document that matches one of array
I have a document with the bankAccounts
attribute:我有一个带有
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,
},
]
})
So a user can have many bank accounts.所以一个用户可以有很多银行账户。 It can have
currency: USD
and a currency: EUR
bank accounts.它可以有
currency: USD
和currency: EUR
银行账户。
I'm querying the users and retrieving one user with an array of currencies this user have, so in this example my array would be ['USD', 'EUR']
.我正在查询用户并使用该用户拥有的一系列货币检索一个用户,因此在此示例中,我的数组将是
['USD', 'EUR']
。
I need to make a new query, to a new collection, searching all orders that match one of the currencies in the array:我需要对新集合进行新查询,搜索与数组中一种货币匹配的所有订单:
const orders = await Orders.find({status: "Allocating", currency: oneOfTheArray })
How can I achieve an OR
condition on my query, iterating all currencies in my array?如何在查询中实现
OR
条件,迭代数组中的所有货币?
Thank you in advance先感谢您
Try this尝试这个
const orders = await Orders.find({status: "Allocating", currency: {$in:oneOfTheArray} })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.