Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
None
Description
Currently when the field is an array, $type operation on that field matches any inner element. { $type : 'array' } on that array field will match if the field has a nested array, and it will not return results where the field itself is an array.
To check if a field is an array and if the array is not empty, we can use the following query:
db.collection.find({"answers.vendor": {$elemMatch: {$exists:true}}})
|
To return the document if the field is an array (no matter if it empty or not), we can use the following query:
db.collection.find({$or:[{"answers.vendor": {$elemMatch: {$exists:true}}}, {"answers.vendor":[]} ]})
|
It would be nice to add this to the document.