There are thousands of documents in MongoDB collection and when I run this query it takes lots of time.
This is my db query:
db.collection.aggregate( [
{   $match: commonSearch },
{
    $addFields: {
        "ingestionDate": {
            $toDate: "$commonData.bo_ingestionDate"
        },
        "lastModifiedDate": { $toDate: "$commonData.bo_lastModifiedDate" }
    }
},
{
    $project: {
        "commonData": 1, "data.page_1": 1, documentType: 1,
        isExported: 1, dcn: 1,
        endorserNumber: "$data.page_1.data.H_BARCODE.value",
        "receivedDate": {
            "$dateToString": {
                "format": "%Y-%m-%d",
                "date": "$ingestionDate"
            }
        },
        "exportedDate": {
            "$dateToString": {
                "format": "%Y-%m-%d",
                "date": "$lastModifiedDate"
            }
        }
    }
},
{   $match: searchQuery },
{   $sort: { [sortingKey]: sortingOrder } },
{   $skip: (req.body.pageNumber - 1) * req.body.rowPerPage },
{   $limit: req.body.rowPerPage }
] )
.allowDiskUse(true)
The query takes more time to execute; how to decrease execution time.
 
    