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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:07:03+00:00 2026-06-11T02:07:03+00:00

From MongoDB Documentation If you have a compound index on multiple fields, you can

  • 0

From MongoDB Documentation

If you have a compound index on multiple fields, you can use it to query on the beginning subset of fields. So if you have an index on
a,b,c
you can use it query on [a] [a,b] [a,b,c]

So lets say i have document with this fields

  1. UserID
  2. Name
  3. Country
  4. ExtraField

My Index order is [UserID,Name,Country]

So if i have query like

  var q = (from c in collection.AsQueryable()
                 where c.UserID == UserID
                 where Name = "test"
                 where Country = 1
                 where ExtraField = "check"

                 select c);

Does this query use index for first 3 parameters and then search for ExtraField without index?

If yes, then is it same on this query too

 var q = (from c in collection.AsQueryable()
                 where c.UserID == UserID                   
                 where ExtraField = "check"

                 select c);
  • 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-11T02:07:04+00:00Added an answer on June 11, 2026 at 2:07 am

    The answer to both questions is yes.

    For your first query, the performance will depend on the selectivity of the result set. So if the 3 fields in the index matched a very large number of documents, performance would be slow as all those documents would need to be scanned to match on ExtraField. If only a few documents were matched, performance would be fast.

    Now, if your query didn’t include the first field in the index at all, the index would not be used. The following query, for example, would not be able to use the index:

    var q = (from c in collection.AsQueryable()
                  where Name = "test"
                  where Country = 1
                  select c);
    

    Have a look here for some interesting facts about finding other combinations of fields in the index.

    I would recommend using the explain command when in doubt about questions like this.

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

Sidebar

Related Questions

I have a web page where users can see data from MongoDB on a
I have a simple script to get an export from MongoDB: #!/bin/sh -x QUERY='{
I'm trying to retrieve only a subset of fields from mongodb using Java driver.
I get data from mongodb in php and display fields in table. Can I
I can't seem to find documentation on authentication into mongodb from the C driver.
How can you drop a numeric collection from MongoDB? PRIMARY> db.123456789011.remove({}); Tue Mar 20
I'm using the JavaScript mongodb driver from nodejs. I want to do this query
From the MongoDB command line I can do db.user.update({userid: {$in: [435707147,88513850,466518582]}},{$unset: {f1 : 1}})
I have an applicaton written in PHP that retrieves files from mongoDB Grid collection,
Recently, I have updated from MongoDB 1.6 to MongoDB 2.0. I have populated several

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.