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

Count Is very very slow using aggregation frame work.

    • Type: Icon: Bug Bug
    • Resolution: Incomplete
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • ALL

      I Have 8 million records i created compound index on id,ind_id and is_valid this order.

      I execute below query, I got 0.2 seconds match result but why $sortByCount result comes too slow.
      It takes 2 minutes.

      db.panelist.aggregate(
      
      	// Pipeline
      	[
      		// Stage 1
      		{
      			$match: {"$and":
      			  [{id:{$in:[1,2,5,4]}},
      			  {"ind_id":{$exists:true}}
      			 ]
      			 }
      		},
      
      		// Stage 2
      		{
      			$project: {
      			 "_id":0,
      			 "id":1,
      			 "ind_id":1,
      			"is_valid":1
      			}
      		},
      
      		// Stage 3
      		{
      			$sortByCount:  "$is_valid"
      			
      		},
      	],
      
      	// Options
      	{
      		cursor: {
      			batchSize: 50
      		},
      
      		allowDiskUse: true
      	}
      
      	// Created with Studio 3T, the IDE for MongoDB - https://studio3t.com/
      
      );
      

            Assignee:
            daniel.hatcher@mongodb.com Danny Hatcher (Inactive)
            Reporter:
            samba samba
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: