Altas search is very fast, but getting count times out

Doing text search with indexed fields is very fast, < 1second. Just removing $project and adding $count stage causes timeout. How else can we do this? We want to display the total count to the user.

Sounds weird. Are you sure this is just Atlas? (Have you tried it on a local machine?)
Can you show some code?

What I suspect is that the pipeline with $project can be optimized and the first set of documents can be returned to the application in the first cursor without processing all documents that matches. With $count, it is a different story and matching documents must be processed to obtain the count.

Thanks Jack!,

I get the same behavior from compass, mongo shell python using pymongo. All of the fields in path are indexed. My collection is ~225K documents, avg. size 5.8KB.

Here is pipeline from compass:

pipeline = [{
$search: {
  index: 'atlas_compound',
  text: {
    path: [
      'name',
      'description',
      'keywords'
    ],
    query: 'blue',
   fuzzy: {
      maxEdits: 2,
      prefixLength: 0,
      maxExpansions: 50
    }
  }
}},
 {$count: 'count'}
]

Hi Steeve,

I have no $project. Just a $search and $count.

Do you have a schema?

Sorry, I must have misread

to mean that you had a fast pipeline with a $project that is now timing out after replacing $project with $count.

I often do that when working on a counting or grouping pipeline. I develop with $project to see if I only consider the appropriate documents and I replace $project with $group or $count only at the end.

1 Like

Hi Jack. Atlas search is not available on local install. I did notice that removing fuzzy options reduce the time from about 15secs to 5! Not a solution for me, but it is curious.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.