Mongoose aggregate doesn't return unmatched subdocuments

Viewed 93

I have subdocuments inside documents. And I'm trying to get entire documents if any subdocument provides multiple conditions. It's working right except not showing unmatched subdocuments.

# EXAMPLE DOCUMENT
name: "Sam",
specs: [
  {city: "istanbul", color: "blue"},
  {city: "istanbul", color: "black"},
  {city: "izmir", color: "yellow"}
]
# QUERY
Dudes.aggregate([
    {$unwind: '$specs'},
    {$match: {'specs.city': "istanbul", 'specs.color': "yellow"} }
  ]);

It's returning the matching documents but in documents there is only matched subdocument.

# OUTPUT:
name: "Sam",
specs: [
  {city: "izmir", color: "yellow"}
]
1 Answers
Related