Mongodb find a document with all subdocuments satisfying a condition

mongodb

Solution

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.

Problem

I have Game collection in my DB: ``` var game = { players: [{username:"user1", status:"played"}, {username:"user2", status:"accepted"}] } ``` As far as I understand query like this: `db.games.find({"players.status":"played"})` will give me all games where at least one player has status "played". How can I find games with ALL players having status "played"?

Original source

Related problems