2017-04-09 66 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後,按預期工作。謝謝你的幫助。 –