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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:44:44+00:00 2026-05-23T11:44:44+00:00

db.hello.ensureIndex({array1:1, array2:1}) MongoDB does not allow that, because they say it can get out

  • 0
db.hello.ensureIndex({"array1":1, "array2":1})

MongoDB does not allow that, because they say “it can get out of hand”. However, I know that my arrays will never exceed length of 3. How can I hack MongoDB to allow indexing multiple arrays at once?

When using a compound index, at most
one of indexed values in any document
can be an array. So if we have an
index on {a: 1, b: 1}, the following
documents are both fine:

{a: [1, 2], b: 1} {a: 1, b: [1, 2]}
This document, however, will fail to
be inserted, with an error message
“cannot index parallel arrays”:

{a: [1, 2], b: [1, 2]} The problem
with indexing parallel arrays is that
each value in the cartesian product of
the compound keys would have to be
indexed, which can get out of hand
very quickly.

  • 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-23T11:44:45+00:00Added an answer on May 23, 2026 at 11:44 am

    The short answer to your question is; you don’t. The only option available to you is to store the every unique pair as a single array element. So rather than :

    {a:[1,2], b:[8,9]}
    

    you store

    {ab:[[1,8], [1,9], [2,8], [2,9]]}
    

    Obviously this has a few downsides so it really depends on your specific usecase whether or not this is an appropriate workaround. I do agree however that mongo shouldn’t reject multiple array indexes just for idiot proofing. It’s a good feature for small/low cardinality arrays.

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

Sidebar

Related Questions

Hello, Im working on a solution for Android that will record calls (both out
Hello i am trying to find out how can i print a file which
Hello can anybody solve this please I'm creating the object in the action class
Hello I am compiling a program with make but I get the error of
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello there i'm trying to create a form with Zend_Form that will enable my
Hello I have two text inputs which get their values from a datepicker. What
Hello i been trying to get a tokenizer to work using the boost library
hello i wanted to build I get $date and $date1 from form xxx. I
Hello guys can you please help me with this problem. When a simple image

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.