Mongodb find a document with all subdocuments satisfying a condition

前端 未结 3 1137
时光说笑
时光说笑 2020-12-11 03:30

I have Game collection in my DB:

var game = {
  players: [{username:\"user1\", status:\"played\"},
            {username:\"user2\", status:\"accepted\"}]
}
<         


        
3条回答
  •  我在风中等你
    2020-12-11 03:44

    If you only have one other status than "played" use the query:

    db.games.find({ "players.status": { $ne:"accepted" } })
    

    You can adjust the query to handle more status values, as long as they are all known at the time of the query.

提交回复
热议问题