Spring MongoRepository @Query JSONParseException

时间:2017-04-09 12:03:27

标签: java spring mongodb mongorepository

我有以下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 个答案:

答案 0 :(得分:0)

以下是覆盖该更改的票证。它已得到解决和释放。尝试启动版本1.5.2及之后或Spring mongo 1.10.1及之后。

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