Spring 数据中的@ExistQuery mongodb

@ExistQuery in Spring data mongodb

您好,我想在 spring mongo 存储库中进行 exist 查询。我读到了 @ExistQuery 但我不知道如何在里面写查询,我现在的方法:

    @ExistsQuery("{ 'userAccount.socialTokenId': ?1}")
    boolean existBySocialAccountId(String socialAccountId);

但我收到 IndexOutOfBoundsException,'userAccount' 是一个包含变量 socialTokenId 的对象列表。我知道我可以获得整个用户对象并自己找到它,但我想优化我的查询:)。

我认为您的问题是参数的索引为零,因此没有索引为 1 的参数,这导致 IndexOutOfBoundsException

尝试将您的代码更改为以下内容:

@ExistsQuery("{ 'userAccount.socialTokenId': ?0}")
boolean existBySocialAccountId(String socialAccountId);