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

  • Home
  • SEARCH
  • 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 6921483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:16:57+00:00 2026-05-27T10:16:57+00:00

I currently have a MongoDB setup with a fairly large database (about 250m documents).

  • 0

I currently have a MongoDB setup with a fairly large database (about 250m documents). At present, I have one main collection that has the majority of the data, which has a single index (time). This results in acceptable query times when only the time is in the where part of the query (the index is used).

The problem is when I need to use a compound key – the time index uses about 2.5GB of memory, and I only have 4GB on the server, so I don’t want to create a compound key index since that will prevent all indexes from fitting in memory and thus slow things down a lot.

So my question is this: can I query first for time, and then query that subset for the other variables?

I should point out that I am using the Ruby driver.

At the moment, my query looks like this (this is very slow):

trade_stop_loss_time = ticks.find_one({
        "time" => { "$gt" => trade_time_open, "$lte" => trade_time_close },
        "bid"  => { "$lte" => stop_loss_price } 
    }).sort({"time" => 1})

Thanks!

  • 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-27T10:16:58+00:00Added an answer on May 27, 2026 at 10:16 am

    If you simply perform the query you present, the database should be smart enough to do exactly that.

    The query you have should basically filter down the candidate set using the time index, then scan the remaining objects for the bid parameter. This should be a lot more efficient than doing the scan on the client.

    You should definitely run explain() on your query to find out what it’s doing. If it uses an index (BtreeCursor) and the number of scanned objects is just the number of items in the given time frame, it’s doing fine. I don’t think there’s a better way than that, given your constraints. Doing the same operation on the client will definitely be slower.

    Of course, a limit and a small time frame will help to make your query faster, but these might be external factors. mongostat might also help to find the problem.

    However, if your documents and/or time spans are large, it might still be better to add the compound index: loading a lot of large documents from disk (since your RAM is already full) will take some time. Paging the index from disk is also slow, but it’s much less data.

    A good answer can be given only be experiment.

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

Sidebar

Related Questions

I currently have an MS Access application that connects to a PostgreSQL database via
I currently have a DetailsView in ASP.NET that gets data from the database based
I currently have a mongoDB setup with a mongos server, a config server, and
I'm currently building a webserver in nodeJS that'll be using mongoDB. One of the
I'm using pymongo and currently have a single collection. The collection holds documents representing
I have a MongoDB collection with documents in the following format: { _id :
I have a slowly growing collection of about 3 million tagged documents and I
I currently have an existing database and I am using the LINQtoSQL generator tool
I currently have a fairly robust server-side validation system in place, but I'm looking
I have a collection where I only ever need to look up documents by

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.