spring数据mongo查询嵌套文档列表

3z6pesqy  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(258)

我有以下mongo文件

{
    "_id" : ObjectId("5fc4b2061c2dab6097d460eb"),
    "customerReferenceId" : "170901040",
    "firstName" : "first_1032",
    "lastName" : "last_1032",
    "email" : "1032@test.com",
    "phone" : "0501032103",
    "registrationIp" : "80.80.80.1032",
    "commonData" : {
        "localId" : "000001032",
        "bankAccounts" : [ 
            {
                "id" : "5fc4b2061c2dab6097d460f0",
                "webUiId" : NumberLong(396),
                "bankCode" : 12,
                "branchCode" : 1,
                "bankAccountNumber" : "19053",
                "bankDetails" : "bank",
                "freeText" : "Free text",
                "productTypeSource" : "LENDER",
                "bankAccountsCoOwners" : []
            }
        ]
    }
}

mongo存储库是

@Repository
public interface CustomerRepository extends ExtendedRepository<CustomerEntity, String> {

    Optional<CustomerEntity> findByCommonDataLocalId(String localId);

    Optional<CustomerEntity> findByEmail(String email);

    @Query("{ 'commonData.bankAccounts.bankCode' : ?0, 'commonData.bankAccounts.branchCode' : ?1 , 'commonData.bankAccounts.bankAccountNumber' : ?2 }")
    Optional<CustomerEntity> findByBankAccount(String bankCode, String branchCode, String bankAccountNumber);

我正试图通过客户的银行代码、银行分行和银行帐号来查询客户。存储库中的前两个查询工作正常。对于第三个,我不认为有一种方法没有

@Query

但是现在第三个查询出错了,我无法得到客户

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题