Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8857075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:30:18+00:00 2026-06-14T14:30:18+00:00

I run this command: db.ads_view.aggregate({$group: {_id : $campaign, action : {$sum: 1} }}); ads_view

  • 0

I run this command:

db.ads_view.aggregate({$group: {_id : “$campaign”, “action” : {$sum: 1} }});

ads_view : 500 000 documents.

this queries take 1.8s . this is its profile : https://gist.github.com/afecec63a994f8f7fd8a

indexed : db.ads_view.ensureIndex({campaign: 1});

But mongodb don’t use index. Anyone know if can aggregate framework use indexes, how to index this query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:30:19+00:00Added an answer on June 14, 2026 at 2:30 pm

    The $group operator is not one of the ones that will use an index currently. The list of operators that do (as of 2.2) are:

    $match
    $sort
    $limit
    $skip
    

    From here:

    http://docs.mongodb.org/manual/applications/aggregation/#pipeline-operators-and-indexes

    Based on the number of yields going on in the gist, I would assume you either have a very active instance or that a lot of this data is not in memory when you are doing the group (it will yield on page fault usually too), hence the 1.8s

    Note that even if $group could use an index, and your index covered everything being grouped, it would still involve a full scan of the index to do the group, and would likely not be terrible fast anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run this command in the bash terminal it works: awk '{ sum
I run this command : select * from LIST where JCODE = 8 and
I have run this command with root: [root@localhost git-shell-commands]# ssh git@192.168.1.12 git@192.168.1.12's password: Last
How do I run this command with subprocess? I tried: proc = subprocess.Popen( '''ECHO
I can run this command in SqlManager to detach the db ALTER DATABASE mydb
I am logged into my server as root and tried to run this command:
how to insert inner array in mongodb using php I run this command in
How can I run this on linux command line when my username has an
I am trying to run this dreadfully simple command in Bash java -cp nasa-top-secret.jar
I have this command to go to every directory and once there run some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.