我有一个文档类
@Document(collection = "games")
public class Game {
@Indexed
private String gameId;
private Player mainPlayer;
private Player secondPlayer;
private List<Player> players;
...
播放器类是
@Document(collection = "moves")
public class Player {
@Indexed
private String id;
boolean gameOver=false;
boolean isWinner=false;
boolean isMainPlayer=false;
,并且需要查询mongodb中的所有游戏,其中包含一个具有特定ID的玩家,并且仅包含一个玩家。 到目前为止,我已经完成了存储库代码
@Repository
public interface GameRepository extends ReactiveMongoRepository<Game, String> {
@Query{ $and: [ { players: { $size: 1 } }, { players: { id: ?0 } } ] }
Flux<Game> getGamesWithOnlyOnePlayer(String playerId);
}
但是它不起作用...有人知道如何解决此问题吗?
谢谢