Find mongo docs with empty object in array
arrays, mongodb
Solution
If you're looking to find docs where `arrayProperty` contains at least one `{}` then it's just:
db.collection.find({ arrayProperty: {} })
If you're looking to find docs where `arrayProperty` only contains either one or two `{}`:
db.collection.find({ arrayProperty: {$in: [ [{}], [{}, {}] ] } })
Problem
I have a Mongo collection with an array property, and the array has "empty" objects in it. What query can I use to target these non-empty arrays that have only {}? I've tried combinations of `$exists` and `$where` to no avail. Examples of data I need to target: ``` "arrayProperty" : [ {} ] ``` and ``` "arrayProperty" : [ {}, {} ] ``` EDIT: Here's an example of the schema: ``` { "_id" : ObjectId("53b1ca583d597ce7cbd54646"), "arrayProperty" : [ { "serialNumber" : "abc123", "rfid" : "xyz098", "size" : 95, "points" : 50, "frequency" : "Every day", "dateAssigned" : ISODate("2011-02-10T15:27:39.000Z") } ] } ```