Mongodb Atlas Search is slow on count or sort with huge data set

I have used an atlas search for finding records of first name and last name. which return 10k records. I would like to display with the page so I used the count operator to get the count. but when I use the count it not very slow. it is the same scenario when I use sort. could someone help me with this?

Now it takes more than 10 seconds to return the response.

{
       "index":"subscriptions_search",
       "compound":{
          "should":[
             {
                "autocomplete":{
                   "query":"pe",
                   "tokenOrder":"any",
                   "fuzzy":{
                      "prefixLength":2
                   },
                   "path":"mainSubscriberFullProperty.lastName"
                }
             },
             {
                "autocomplete":{
                   "query":"pe",
                   "path":"mainSubscriberFullProperty.firstName",
                   "tokenOrder":"any",
                   "fuzzy":{
                      "prefixLength":2
                   }
                }
             }
          ],
          "minimumShouldMatch":1
       }
    },
 {
      $count: "identifier"
    }


Read more here: https://stackoverflow.com/questions/66278095/mongodb-atlas-search-is-slow-on-count-or-sort-with-huge-data-set

Content Attribution

This content was originally published by Bathri Nathan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: