Remove empty nested array field after aggregation lookup?

Hello, I’m new to working with mongodb and am trying to figure something out. I’ve set up a mongodb playground to demonstrate what I’m doing and trying to solve.

You can see I have three collections, which results in a nested array situation. Through a lot of Googling and trial and error I managed to come up with a lookup stage shown that populates the arrays for me. Not sure if that is the best way to do it, but it works.

The final issue I have is the resulting array documents that did not have a nested array in them to begin with now have an empty nested array in them. Look at “Array Document 2” as an example and notice the empty “nestedArray” since it did not have a “nestedArray” in its source data.

Is there a way to skip documents in the lookup stage that do not contain this nested array to begin with so an empty nested array is not added to them. Alternatively, could I remove the empty nested array after the lookup some how?

I’ve seen some potential solutions online, but have so far had no luck with any of them. For example, a match stage doesn’t appear to be any good as it completely filters out the offending documents. Another example with a project stage seems to involve specify which fields are visible/hidden however this is a maintenance issue every time the field structure of the documents change. Some other examples use an unwind stage, but are overly convoluted and I could never get them to work. I also read something that indicated that unwind should be avoided if possible for some reason.