繁体   English   中英

Spring MongoRepository @Query JSONParseException

[英]Spring MongoRepository @Query JSONParseException

我有以下MongoDB实体:

public class Player {

    @Id 
    private String id;

    private String username;

    private int rating;

    private boolean active;
}

public class Match {

    @Id
    private String id;

    @DBRef
    private Player playerOne;

    @DBRef
    private Player playerTwo;
}

我尝试获得所有玩家的比赛。 这意味着,例如,我有当前玩家,并且当playerOne == 当前玩家 playerTwo == 当前玩家时,应该返回匹配列表以进行匹配。 我为此使用了MongoRepository:

public interface MatchRepository extends MongoRepository<Match, String> {

    @Query(value = "{'$or': [{'playerOne.id': ?0}, {'playerTwo.id': ?0}]}")
    List<Match> findByPlayerId(String playerId);
} 

当我执行findByPlayerId方法时,出现以下错误:

Caused by: com.mongodb.util.JSONParseException: {'$or': [{'playerOne.id': "58ea191756a4302290fff9b1"}, {'playerTwo.id': "58ea191756a4302290fff9b1"0}]}

我在错误消息的末尾发现了一个奇怪的0字符: "0}]}

我也做了一些解决方法,并将相同的player.id用作第二个方法参数,它可以正常工作:

@Query(value = "{'$or': [{'playerOne.id': ?0}, {'playerTwo.id': ?1}]}")
List<Match> findByPlayerId(String playerId, String palyerId2);

您有什么主意,为什么第一种方法会返回JSONParseException?

这是涵盖该变更的票证。 它已解决并发布。 尝试启动1.5.2版及更高版本,或尝试使用mongo 1.10.1及更高版本。

https://jira.spring.io/browse/DATAMONGO-1603

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM