MongoDB - Check if value exists for a field in a document
You need the $size operator. To find something with no elements do the following
db.collection.find({ channels: {$size: 0} })
If you know you have a fixed size then do that
db.collection.find({ channels: {$size: 2} })
Otherwise reverse that with $not
db.collection.find({ channels: {$not:{$size: 0}} })
And you can combine with $and:
db.collection.find({ $and: [
{ channels: {$not:{$size: 0}} },
{ channels: {$exists: true } }
]})
I did it using this :
db.event_copy.find({'channels.0' : {$exists: true}}).count()
Check out the size operator here
db.event_copy.find( { channels: { $size: 0 } } );