我有以下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;
}我试着得到所有球员的比赛。这意味着,当playerOne、==、current player、或 playerTwo ==当前播放器时,应该返回当前播放器和比赛列表。为此,我使用了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吗?
发布于 2017-04-09 20:28:19
这是那张零钱的票。它已经解决并释放了。尝试引导版本1.5.2和之后或Springmongo1.10.1及之后。
https://stackoverflow.com/questions/43306460
复制相似问题