I have a game object that has a boolean isOpen and a sub document playersthat is an array of players. I'd like to find a game that is open for players to join that contains less than 5 players. How do I do this? Preferably without using $where
//made up sample for reference
const sampleDocument = {
isOpen: true,
isOver: false,
players : [{
socketID: 'sldfjskdfjsjdfsdfj',
isBot: false,
name: 'NickName',
}],
startTime: 32343234
The relevant line of code
let game = await Game.findOne({isOpen: true, /*players : { $size: {$lt: 5} }*/})