I’m doing searches over my collection.
{
'$search': {
'compound': {
'must': [
{
'text': {
'query': 'bananas',
'path': 'description'
}
}
]
}
}
}, { '$limit': 10}
Now,
Including the Searched results, I also need to get
the total no. of matched docs.
For doing this . I’m using $count
I’ve to run two $search
aggregation
separately in my Backend.
1st aggregation
returns Searched Results only in an array
format
2nd aggregation
returns the total count of the document
Then I combine those two output to a single array manually.
Similar to:
Promise.all( aggegration1, aggegration2)
Isn’t that any way to combine those two aggregation in single stage with $facet
?
which can return the both searched results and count ?
Thanks