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 7683643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:50:29+00:00 2026-05-31T18:50:29+00:00

I have one collection numbers with 200000 document object with {number: i} i =

  • 0

I have one collection “numbers” with 200000 document object with {number: i} i = 1 to 200000.

Without any index $gt: 10000 gives nscanned 200000 and 115 ms.
With index on number $gt: 10000 gives nscanned 189999 and 355 ms.

Why more time with indexing?

> db.numbers.find({number: {$gt: 10000}}).explain()
{
    "cursor" : "BasicCursor",
    "nscanned" : 200000,
    "nscannedObjects" : 200000,
    "n" : 189999,
    "millis" : 115,
    "nYields" : 0,
    "nChunkSkips" : 0,
    "isMultiKey" : false,
    "indexOnly" : false,
    "indexBounds" : {

    }
}

> db.numbers.ensureIndex({number: 1})

> db.numbers.find({number: {$gt: 10000}}).explain()
{
    "cursor" : "BtreeCursor number_1",
    "nscanned" : 189999,
    "nscannedObjects" : 189999,
    "n" : 189999,
    "millis" : 355,
    "nYields" : 0,
    "nChunkSkips" : 0,
    "isMultiKey" : false,
    "indexOnly" : false,
    "indexBounds" : {
            "number" : [
                    [
                            10000,
                            1.7976931348623157e+308
                    ]
            ]
    }
}
  • 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-05-31T18:50:30+00:00Added an answer on May 31, 2026 at 6:50 pm

    In this case, the index doesn’t help because your matching result set consists of almost the entire collection. That means it has to load into RAM and traverse most of the index, as well as load into RAM and traverse the documents themselves.

    Without the index, it would just do a table scan, inspecting each document and returning if matched.

    In cases like this where a query is going to return almost an entire collection, an index may not be helpful.

    Adding a .limit() will speed the query up. You can also force the query optimizer to not use the index with .hint():

    db.collection.find().hint({$natural:1})
    

    You could also force the query to provide the result values directly from the index itself by limiting the selected fields to only the ones you’ve indexed. This allows it to avoid the need to load any documents after doing the index scan.

    Try this and see if the explain output indicates "indexOnly":true

    db.numbers.find({number: {$gt: 10000}}, {number:1}).explain()
    

    Details here:

    http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields#RetrievingaSubsetofFields-CoveredIndexes

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

Sidebar

Related Questions

I have a collection of custom entity objects one property of which is an
I have a collection of static libraries (.lib) files one of which may have
I have a collection of elements, each one with a name and a subcollection
I have a Queue that contains a collection of objects, one of these objects
Another easy one hopefully. Let's say I have a collection like this: List<DateTime> allDates;
I have a problem with a data collection wizard. My wizard has a number
I have a collection of sets with numbers in it. Say A = {-2,
I have a Customer object which has a collection of ContactNumbers. Is it possible
I have an object that has a child collection: class Person { public string
I am searching for a method to intersect my array collections. I have one

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.