Query common name in objects with different names


I am trying to query the name in a list of nested Objects that have different field names.
Every example has a name field, but I am unable to filter on it. I’ve tried “tasks…name” but that does not work in Compass - { “tasks…name”: “restCall” }.

Screen Shot 2022-08-03 at 10.39.19 AM


Hello, @Austin_Summers,

The query will not provide a filtered result in the nested array, for that you have to use an aggregation query with $filter operator to filter the nested array by providing your conditions.

Your example has all field names perfectly aligned. I need a way around that.

The difficulty is your schema. The fact that you repeat the field name of Tasks as a field inside the subdocuments is a clue about an issue with the schema. Tasks should be an array since the field name is sufficient to identify the task. With an array you would have a schema that uses the attribute pattern.

This being out of my chest, see if $objectToArray can perform the transformation you need to use $filter as hinted by @turivishal.