Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-44032

Mongodb Count is slow

    • Type: Icon: Question Question
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.2.0
    • Component/s: None
    • Labels:
      None

      Hi,
      I am trying to improve count using covered queries but its taking ~5sec to return the response.

      Is this behavior expected or there is something I can do to improve this.

      Please find details below-

      There is collection with 6 million records

      consider each document to be something like this

      { "_id": "523453252", "type": "test" }

      i have a single field index on "type"

       when I execute following command
      db.test.explain("executionStats").find({type:{$in:["test","test1","test2"]}},{type:1,_id:0}).count()

      the number of keys examined are ~5.9 million
      number of docs examined are 0
      even though there are no docs examined i.e nothing is loaded from disk
      and the query is using only index the count is taking ~5sec
      Please let me know if there is anything that can be done to improve count response time.

        1. scr1.png
          scr1.png
          204 kB
        2. scrnsht.png
          scrnsht.png
          210 kB

            Assignee:
            eric.sedor@mongodb.com Eric Sedor
            Reporter:
            virinchisamineni@gmail.com virinchi samineni
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: