What if mongo queries count very slowly?

I currently have a query using mongodb3.4, that needs to be paged. Paging needs to return the total number and number of pages.
but that"s the problem. Paging queries are fast, but counting is slow

. The

count statement is as follows:

db.message.find(
    {
        "field_1":"ajian",
        "field_2":{ "$exists": true },
        "field_3":{ "$exists": true },
        "field_4":{ "$exists": true },
        "field_5":{"$regex":value1},
        "field_6":{"$regex":value2}
    }
).count()

it takes 2.5 seconds to return the result!
the info results of my explain are as follows:

{
    "queryPlanner" : {
        "plannerVersion" : 1,
        "namespace" : "engine.message",
        "indexFilterSet" : false,
        "parsedQuery" : {
            "$and" : [ 
                {
                    "field_1" : {
                        "$eq" : "ajian"
                    }
                }, 
                {
                    "field_2" : {
                        "$regex" : ""
                    }
                }, 
                {
                    "field_3" : {
                        "$regex" : ""
                    }
                }, 
                {
                    "field_4" : {
                        "$exists" : true
                    }
                }, 
                {
                    "field_5" : {
                        "$exists" : true
                    }
                }, 
                {
                    "field_6" : {
                        "$exists" : true
                    }
                }
            ]
        },
        "winningPlan" : {
            "stage" : "COLLSCAN",
            "filter" : {
                "$and" : [ 
                    {
                        "field_1" : {
                            "$eq" : "ajian"
                        }
                    }, 
                    {
                        "field_2" : {
                            "$regex" : ""
                        }
                    }, 
                    {
                        "field_3" : {
                            "$regex" : ""
                        }
                    }, 
                    {
                        "field_4" : {
                            "$exists" : true
                        }
                    }, 
                    {
                        "field_5" : {
                            "$exists" : true
                        }
                    }, 
                    {
                        "field_6" : {
                            "$exists" : true
                        }
                    }
                ]
            },
            "direction" : "forward"
        },
        "rejectedPlans" : []
    },
    "executionStats" : {
        "executionSuccess" : true,
        "nReturned" : 1537253,
        "executionTimeMillis" : 2536,
        "totalKeysExamined" : 0,
        "totalDocsExamined" : 1610191,
        "executionStages" : {
            "stage" : "COLLSCAN",
            "filter" : {
                "$and" : [ 
                    {
                        "field_1" : {
                            "$eq" : "ajian"
                        }
                    }, 
                    {
                        "field_2" : {
                            "$regex" : ""
                        }
                    }, 
                    {
                        "field_3" : {
                            "$regex" : ""
                        }
                    }, 
                    {
                        "field_4" : {
                            "$exists" : true
                        }
                    }, 
                    {
                        "field_5" : {
                            "$exists" : true
                        }
                    }, 
                    {
                        "field_6" : {
                            "$exists" : true
                        }
                    }
                ]
            },
            "nReturned" : 1537253,
            "executionTimeMillisEstimate" : 2417,
            "works" : 1610193,
            "advanced" : 1537253,
            "needTime" : 72939,
            "needYield" : 0,
            "saveState" : 12588,
            "restoreState" : 12588,
            "isEOF" : 1,
            "invalidates" : 0,
            "direction" : "forward",
            "docsExamined" : 1610191
        },
        "allPlansExecution" : []
    },
    "serverInfo" : {
        "host" : "secret",
        "port" : 27017,
        "version" : "3.4.10",
        "gitVersion" : "2234234232325323343"
    },
    "ok" : 1.0
}

Why is mongo"s count count so slow? How do the gods solve this problem when they do paging? How should I solve this problem?

Mar.04,2021

simply put, a query that cannot hit any index requires a full table scan, which is, of course, slow. You need to add the appropriate index.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e93214-68ba2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e93214-68ba2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?