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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:07:58+00:00 2026-06-05T02:07:58+00:00

After playing with db.largecollection.find( { $or : [ { identifierX : sha1_hash123 } ,

  • 0

After playing with

db.largecollection.find( { $or : [ { identifierX : “sha1_hash123” } , { identifierY : “md5_hash456” } , { identifierZ : “another_hash789” } ] } )

I checked the indexes that mongodb prepared automatically. in addition to the “single” ensureIndex for the identifiers x/y/z, there is a identifierX_1_identifierY_1_identifierZ_1 now and performance is down 🙁

Do you have an idea or tip how to explain to mongodb that it’s faster to use the indexes for the single identifiers because i do not have $and, but $or queries?

Thx

  • 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-05T02:07:59+00:00Added an answer on June 5, 2026 at 2:07 am

    MongoDB doesn’t create indexes on its own. It’s something that an application, user, or framework does. For your query, MongoDB could only use an index for either of identifierX, identifierY or identifierZ. However, if you don’t have such an index then of course none will be used. The identifierX_1_identifierY_1_identifierZ_1 index can not be used for this query.

    In this case, you will probably need to make an index for all of this identifiers:

    db.ensureIndex( { 'identifierX' : 1 } );
    db.ensureIndex( { 'identifierY' : 1 } );
    db.ensureIndex( { 'identifierZ' : 1 } );
    

    MongoDB can only use one index at a time, and it will try to pick the “best” one. Try using explain to see which indexed is being picked:

    db.largecollection.find( { $or : [
        { identifierX : "sha1_hash123" },
        { identifierY : "md5_hash456" },
        { identifierZ : "another_hash789" }
    ] } ).explain();
    

    That should give you some ideas on which index is being used.

    There is an exception for $or though, where MongoDB can use a different index for each of the parts and de-dup for you. It’s here in the docs. It would (of course) still not use the compound index, and you need the indexes that I’ve written here above.

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

Sidebar

Related Questions

After playing with PHP, I discovered that true is returned as 1 and false
After playing with hidden divs ( display:none ), I've noticed that the browser does
After playing around with haskell a bit I stumbled over this function: Prelude Data.Maclaurin>
After playing quite a bit of Bad Company 2 over the last month, I'm
Hello :) After playing around for a bit, I've come up with the following
Update: After playing around with this for a few hours, went with a multi-query
I am in the process of creating a synthesiser for iOS. After playing around
So i'm trying out MVC after only playing with it some time ago. Need
After installing Monobjc and playing around with the Monobjc Application Project under C# in
Alright, so after a few hours of me playing around to no avail, I

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.