2017-04-09 59 views
0

我有以下的MongoDB实体:春MongoRepository @Query JSONParseException

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; 
} 

我试图让所有球员的比赛。这意味着e.g我有当前玩家和匹配列表应匹配返回时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方法I中错误检索到:

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

我注意到错误消息的结束奇怪0字符:"0}]}

我也做了一些解决方法,并通过相同的player.id作为第二个方法的参数,它工作的fi ne:

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

您对第一种方法返回JSONParseException有任何想法吗?

+0

您使用的是哪个版本的spring boot或spring-data-mongodb? –

+0

我使用spring boot 1.5.1.RELEASE。 –

回答

0

这是覆盖这个变化的票。它已经解决并发布。尝试启动版本1.5.2以及之后或者春天蒙戈1.10.1以及之后。

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

+0

完美,升级到1.5.2后,按预期工作。谢谢你的帮助。 –