Count total number of objects inside multiple fields

Hi everybody.

I have a firm Object, which has a offices field. This offices is an array of objects that has the following structure:

offices[0] = 
{ value: {
   .... other fields,
   lawyers: Array of lawyer object

How can I write an aggregation that returns just the firms with LESS than 5 lawyers in total? Take in consideration that a firm can have multiple offices and these offices can have multiple lawyers.
Thank you very much !

Hi @Teodor_Aspataritei - Welcome to the community.

Wondering if you still require assistance with this? If so, would you be able to provide the full sample document as well as the expected output?

In the meantime, based off the initial description, perhaps one of the below operators may help although it’s difficult to say without the full structure of the document(s) and whether or not they all have the same structure: