MongoDB Lookup Returns an empty array, only when there is no data
The reason is $unwind
. Unwind default behaviour of preserveNullAndEmptyArrays
is false
. Which means in short is if the array is empty or null, remove the document when deconstructing. If you dont need to remove, you can make it as true
. So when your array doesn't have any element, the document is removed. Thats you you are getting empty array