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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:45:06+00:00 2026-06-10T04:45:06+00:00

I have a mongodb collection, features, having 3 fields: name, active, weight. I will

  • 0

I have a mongodb collection, “features”, having 3 fields: name, active, weight.
I will sort features by weight descending:

db.features.find({active:true},{name:1, weight:1}).sort({weight:-1})

for optimization, i create index for it:

db.features.ensureIndex({'active': 1, 'weight': -1})

I can see it works well when using explain() in query.

However, when i query it by weight ascending, i suppose the index i just created will not work and i need to create another index on weight ascending.
Query:

db.features.find({active:true},{name:1, weight:1}).sort({weight:1}).explain()

when i use explain() to show how index working, i find it prints out:

"cursor" : "BtreeCursor active_1_weight_-1 reverse",

does the index reverse mean the query is optimized by the index?

generally, do i need to create 2 index like ascending on weight and descending on weight if i will sort it by weight ascending in some case and descending in other cases?

  • 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-10T04:45:08+00:00Added an answer on June 10, 2026 at 4:45 am

    As you can see from this document, when explain() outputs BtreeCursor, it means that an index was used. When an index is used, indexBounds will be set to indicate the key bounds for scanning in the index. However, if the putput showed BasicCursor, it indicates a table scan style operation.

    So based on what you’ve said, from the explain() results, you can see that you’re using a BTree Cursor on the index named active_1_weight_-1 and the reverse means that you’re iterating over the index in reverse order.

    So no, you don’t need to create separate indexes.

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

Sidebar

Related Questions

I have mongodb running and using morphia. Having a Collection of BatchData Documents and
I have a MongoDB collection and need to find the max() value of a
I have several documents in a MongoDB Collection, with a field 'name' (which is
I have found a collection in one of our MongoDB databases with the name
I have to sort a mongodb collection in ruby via the mongodb driver.When I
I have the following document structure inside a mongodb collection: { _id: XXX, Name:
I have a MongoDB collection with data that was not saved through my Derby
I have simple MongoDB collection and I am using SLIM micro-framework to develop a
I have 10000 documents in one MongoDB collection. I'd like to update all the
Let's assume that I have a collection in mongodb, where all of its documents

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.