我有以下的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有任何想法嗎?
您使用的是哪個版本的spring boot或spring-data-mongodb? –
我使用spring boot 1.5.1.RELEASE。 –