For the mentioned concern, what we need to do is to find the total count while limiting the number of results thus obtained. Since, the code provided is of older version of MongoDB, hence I’m sharing the answer based on the current MongoDB. So, for this concern we can use $facet. This will allows you to perform multiple operation in the same aggregation pipeline. Using this we can get total count of records while limiting the number of results in one single query.