I am working on a complex pagination aggregate query and I am trying to see what Mongo is and isn't capable of doing. I followed this question here, and all works well except for when there is no data returned.
Mongo returns: { metadata: [], data: [] }
, but I want to see if it's possible to return
{ metadata: [ { count: 0 } ], data: [] }
for the Front-End to handle easier. So far I haven't been able to achieve this.
Here's a snippet of the $facet pipeline I'm using :
{
"$facet": {
"metadata": [{
"$count": "total"
}],
"data": [{
"$skip": 0
}, {
"$limit": 10
}]
}
}
Of course this can be done after the query on the back-end, but I'm really wanting Mongo to handle it.