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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:34:23+00:00 2026-05-30T22:34:23+00:00

Ensuring an index on a element of an array does not work as expected

  • 0

Ensuring an index on a element of an array does not work as expected for me.

E.g. with the following data

> db.test.find()
{ "_id" : 7891236423, "arr" : [ "a", "b", "c" ] }
{ "_id" : 7891236424, "arr" : [ "b", "c", "d" ] }
{ "_id" : 7891236425, "arr" : [ "b", "c", "a" ] }
>

the following query works as expected when there is no index

> db.test.find({"arr.0":"a"})
{ "_id" : 7891236423, "arr" : [ "a", "b", "c" ] }
>

but the same query does not return a result if I try to create an index on arr.0

> db.test.ensureIndex({"arr.0":1})
> db.test.find({"arr.0":"a"})
>

I do not understand what is happening here, in my opinion an index should never have an effect on the returned data. Or should it?

Is this a bug? Or index abuse? I’d be happy for any explanations for this behavior, and even happier for any hints how I can achieve an index on a single array element.

PS: I know that I can create an index on arr and query arr first before querying arr.0, which is a valid workaround for the given example. But this does not help as soon as I need to sort a huge amount of data by arr.0 (MongoDB demands an index for this)

  • 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-30T22:34:25+00:00Added an answer on May 30, 2026 at 10:34 pm

    This is a known problem with the v0 indexes used in 1.8 and prior. The new v1 indexes in 2.0+ support this. Upgrading to 2.0.3 should solve your problem. You can find instructions on upgrading to 2.0 here: http://www.mongodb.org/display/DOCS/2.0+Release+Notes#2.0ReleaseNotes-Upgrading

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

Sidebar

Related Questions

Does python provide a way to find the children of a child process spawned
How is the following demo code thread-safe? We are ensuring whether the value is
I've been binding submit events to forms, and ensuring that they do not break
I read somewhere that calling ensureIndex() actually creates a collection if it does not
What would be the process for ensuring that the code works as expected across
For concurrency and ensuring the integrity of the data, how would you obtain a
I want find a platform/language agnostic solution to ensuring the origin of a FORM
Although I love the git history rewrite feature, how does one go about ensuring
I am using the following style for ensuring that whatever my current page URL,
I want to append a class .Appear only after ensuring the element has been

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.