I have 10 million docs in my collection, I just want to get the total count for a query I’m using atlas search.
let data = await Product.aggregate(
[
{
'$search': {
// index: 'default',
'text': {
'query': query,
// path: {
// 'wildcard': '*'
// }
'path':['title','description']
}
},
},
{
$count: "total"
},
// {$facet : { result : [{$limit : 40 } ] , total : [{$count:"total" }]}}
// {
// $limit: 80
// },
// {
// $skip: pageNumber > 0 ? ( ( pageNumber - 1 ) * nPerPage ) : 0
// }
]
)
It takes about an minute to return total count