簡體   English   中英

使用 mongoose 查找與數組之一匹配的文檔

[英]Using mongoose to find a document that matches one of array

我有一個帶有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: USDcurrency: EUR銀行賬戶。

我正在查詢用戶並使用該用戶擁有的一系列貨幣檢索一個用戶,因此在此示例中,我的數組將是['USD', 'EUR']

我需要對新集合進行新查詢,搜索與數組中一種貨幣匹配的所有訂單:

const orders = await Orders.find({status: "Allocating", currency: oneOfTheArray })

如何在查詢中實現OR條件,迭代數組中的所有貨幣?

先感謝您

嘗試這個

const orders = await Orders.find({status: "Allocating", currency: {$in:oneOfTheArray} })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM