Well, remember that for an array field, $type is actually applied to the array elements.
So, will also return Tim’s and Sara’s documents because they both have address array elements that are of type Object. Now, we’ll only try to add the field to documents where “address” is an embedded object and at the same time not an array: Quite some hoops we had to jump through in order to be able to do something as innocent-sounding as adding a missing field to some documents 🙂2.
By the same token, one could now argue that the observed correct execution of db.address.find() in the previous section is actually also inconsistent.
One could expect that when $elem Match goes and checks the individual element fields of “address”, the $type would be executed on each first-level array element.
Ok, we groked that, so what should the following query then return?