0

我有以下 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;
}

我尝试获取所有 Player 的比赛。这意味着,例如,当 playerOne == current playerplayerTwo == current player时,我有当前播放器和匹配列表应返回匹配。我为此使用了 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 吗?

4

1 回答 1

0

这是涵盖该更改的票。已解决并发布。尝试启动 1.5.2 及更高版本或 spring mongo 1.10.1 及更高版本。

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

于 2017-04-09T20:28:19.547 回答