我有以下 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 player或playerTwo == 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 吗?