春季数据mongodb通过集合中的字段查找

时间:2018-07-31 14:00:47

标签: spring-data-mongodb

我有一个文档类

@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);

}                                                                                   

但是它不起作用...有人知道如何解决此问题吗?
谢谢

0 个答案:

没有答案
相关问题