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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:47:40+00:00 2026-06-03T02:47:40+00:00

To quote the docs : When creating an index, the number associated with a

  • 0

To quote the docs:

When creating an index, the number associated with a key specifies the
direction of the index, so it should always be 1 (ascending) or -1
(descending). Direction doesn’t matter for single key indexes or for
random access retrieval but is important if you are doing sorts or
range queries on compound indexes.

However, I see no reason why direction of the index should matter on compound indexes. Can someone please provide a further explanation (or an example)?

  • 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-03T02:47:41+00:00Added an answer on June 3, 2026 at 2:47 am

    MongoDB concatenates the compound key in some way and uses it as the key in a BTree.

    When finding single items – The order of the nodes in the tree is irrelevant.

    If you are returning a range of nodes – The elements close to each other will be down the same branches of the tree. The closer the nodes are in the range the quicker they can be retrieved.

    With a single field index – The order won’t matter. If they are close together in ascending order they will also be close together in descending order.

    When you have a compound key – The order starts to matter.

    For example, if the key is A ascending B ascending the index might look something like this:

    Row   A B
    1     1 1
    2     2 6
    3     2 7 
    4     3 4
    5     3 5
    6     3 6
    7     5 1
    

    A query for A ascending B descending will need to jump around the index out of order to return the rows and will be slower. For example it will return Row 1, 3, 2, 6, 5, 4, 7

    A ranged query in the same order as the index will simply return the rows sequentially in the correct order.

    Finding a record in a BTree takes O(Log(n)) time. Finding a range of records in order is only OLog(n) + k where k is the number of records to return.

    If the records are out of order, the cost could be as high as OLog(n) * k

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

Sidebar

Related Questions

Quote from hib official docs: Starting with version 3.0.1, Hibernate added the SessionFactory.getCurrentSession() method.
Quote from Wikipedia : A public key token. This is a 64-bit hash of
I'm trying to fix single quote bug in the code: std::string Index; connection->Open(); String^
a) Quote is taken from http://www.postgresql.org/docs/current/static/tutorial-window.html for each row, there is a set of
I was reading http://www.orchardproject.net/docs/Creating-1-n-and-n-n-relations.ashx and could not get the idea, if it is possible
According to the docs I should be able to have Twilio initiate a call
Google states the following in the AJAX Feed API docs:"Applications MUST always include a
I quote from the SDK docs: Beginning with Android 3.0 (API level 11), Android-powered
I need to create a webpage quite similar to Google's great Docs spreadsheet, but
Quote from Head first html: You can add padding to the top and bottom

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.