【问题标题】:@ExistQuery in Spring data mongodbSpring数据MongoDB中的@ExistQuery
【发布时间】:2019-09-02 20:31:42
【问题描述】:

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

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

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

【问题讨论】:

    标签: mongodb spring-boot spring-data-mongodb


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-03
      • 1970-01-01
      • 1970-01-01
      • 2013-07-22
      • 2017-04-10
      • 1970-01-01
      相关资源
      最近更新 更多