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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:55:20+00:00 2026-06-01T02:55:20+00:00

I have a collection with a relatively big index (but less than ram available)

  • 0

I have a collection with a relatively big index (but less than ram available) and looking at performance of find on this collection and amount of free ram in my system given by htop it’s seems that mongo is not storing full index in the ram. Is there a way to force mongo to store this particular index in the ram?

Example query:

> db.barrels.find({"tags":{"$all": ["avi"]}}).explain()
{
        "cursor" : "BtreeCursor tags_1",
        "nscanned" : 300393,
        "nscannedObjects" : 300393,
        "n" : 300393,
        "millis" : 55299,
        "indexBounds" : {
                "tags" : [
                        [
                                "avi",
                                "avi"
                        ]
                ]
        }
}

Not the all objects are tagged with “avi” tag:

> db.barrels.find().explain()
{
        "cursor" : "BasicCursor",
        "nscanned" : 823299,
        "nscannedObjects" : 823299,
        "n" : 823299,
        "millis" : 46270,
        "indexBounds" : {

        }
}

Without “$all”:

db.barrels.find({"tags": ["avi"]}).explain()
{
        "cursor" : "BtreeCursor tags_1 multi",
        "nscanned" : 300393,
        "nscannedObjects" : 300393,
        "n" : 0,
        "millis" : 43440,
        "indexBounds" : {
                "tags" : [
                        [
                                "avi",
                                "avi"
                        ],
                        [
                                [
                                        "avi"
                                ],
                                [
                                        "avi"
                                ]
                        ]
                ]
        }
}

Also this happens when I search for two or more tags (it scans every item as if were no index):

> db.barrels.find({"tags":{"$all": ["avi","mp3"]}}).explain()
{
        "cursor" : "BtreeCursor tags_1",
        "nscanned" : 300393,
        "nscannedObjects" : 300393,
        "n" : 6427,
        "millis" : 53774,
        "indexBounds" : {
                "tags" : [
                        [
                                "avi",
                                "avi"
                        ]
                ]
        }
}
  • 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-01T02:55:21+00:00Added an answer on June 1, 2026 at 2:55 am

    No. MongoDB allows the system to manage what is stored in RAM.

    With that said, you should be able to keep the index in RAM by running queries against the indexes (check out query hinting) periodically to keep them from getting stale.

    Useful References:

    • Checking Server Memory Usage

    • Indexing Advice and FAQ

    Additionally, Kristina Chodorow provides this excellent answer regarding the relationship between MongoDB Indexes and RAM


    UPDATE:

    After the update providing the .explain() output, I see the following:

    • The query is hitting the index.
    • nscanned is the number of items (docs or index entries) examined.
    • nscannedObjects is the number of docs scanned
    • n is the number of docs that match the specified criteria
    • your dataset is 300393 entries, which is the total number of items in the index, and the matching results.

    I may be reading this wrong, but what I’m reading is that all of the items in your collection are valid results. Without knowing your data, it would seem that every item contains the tag “avi”. The other thing that this means is that this index is almost useless; indexes provide the most value when they work to narrow the resultant field as much as possible.

    From MongoDB’s “Indexing Advice and FAQ” page:

    Understanding explain’s output. There are three main fields to look
    for when examining the explain command’s output:

    • cursor: the value for cursor can be either BasicCursor or BtreeCursor.
      The second of these indicates that the given query is using an index.
    • nscanned: he number of documents scanned.
    • n: the number of documents
      returned by the query. You want the value of n to be close to the
      value of nscanned. What you want to avoid is doing a collection scan,
      that is, where every document in the collection is accessed. This is
      the case when nscanned is equal to the number of documents in the
      collection.
    • millis: the number of milliseconds require to complete the
      query. This value is useful for comparing indexing strategies, indexed
      vs. non-indexed queries, etc.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Collection List<Car> . How to compare each item from this collection with
I have a WPF ComboBox which is databound to a Collection, but depending on
This should be relatively simple for the MVC experts out there, but I'm still
Lets say I have collection of documents with specified longitude and latitude. type is
I'm planning to have collection of items stored in a TCollection. Each item will
for example I have collection foo of documents like that: {tag_cloud:[{value:games, count:10}, {value:girls, count:500}]}
I have Class and Student objects. Both have collection of another as property. Which
We have a collection of entities of type called Unit , collection of entities
I have a collection that use as a cache. How can I limit the
I have a collection of items populated to a drop down menu: string myUserName

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.