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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:29:05+00:00 2026-05-24T11:29:05+00:00

Say I’ve the following design: id | participant_ids …| [ObjectId(…), ObjectId(…)] Now I’m querying

  • 0

Say I’ve the following design:

id | participant_ids
...| [ObjectId(...), ObjectId(...)]

Now I’m querying it this way:

db.events.find({
    participant_ids: ObjectId(...)
});

Which is identical to this:

db.events.find({
    participant_ids: {
        $in: ObjectId(...)
    }
});

I assume there isn’t a difference in performance between those two (but correct me if I’m wrong!).


For each event, there are at least 1 and at most 2 participants. So I could also use the following design:

id | participant_1_id | participant_2_id

… and query it like this …:

db.events.find({
    $or: {
        participant_1_id: ObjectId(...),
        participant_2_id: ObjectId(...)
    }
});

If I wouldn’t use indexing, this probably doesn’t really make a difference, but -of course- I am.

For the first design, I’ld go with the following index:

db.events.ensureIndex({
    participant_ids: 1
});

For the second one, I’ld go with this:

db.events.ensureIndex({
    participant_1_id: 1,
    participant_2_id: 1
});

Both got downsides when you look at their performance.

  • 1st query: Using an Array is probably slower than using a plain key.
  • 2nd query: Using the $or-operator isn’t very fast.
  • 2nd query: Isn’t very scalable, say I’ld want to release the limit of participants sometime, that wouldn’t be possible (you’d have unlimited keys and unlimited items in the $or-part of the queries).

My questions are:
– What design should I use?
– Can I index Arrays? The docs don’t say anything about this, and I’m not sure Arrays are (since their contents can vary really much).

  • 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-24T11:29:06+00:00Added an answer on May 24, 2026 at 11:29 am

    1st query: Using an Array is probably slower than using a plain key.

    I don’t think so. It should be the exact same index-based access path if you have one value (“plain key”) or multiple (“Array”).

    participant_1_id, participant_2_id is just terrible.

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

Sidebar

Related Questions

Say I've got this array: MyArray(0)=aaa MyArray(1)=bbb MyArray(2)=aaa Is there a .net function which
Say i have a few fields like the following: abd738927 jaksm234234 hfk342 ndma0834 jon99322
Say I have this: private list<myClass> myCollection; Is there a programming idiom to shorten
Say I have a SqlAlchemy model something like this: from sqlalchemy.ext.declarative import declarative_base from
Say I want to test this module: import osutils def check_ip6(xml): ib_output = osutils.call('iconfig
Say I have a LINQ-to-XML query that generates an anonymous type like this: var
Say I have the following template function: template <class T> void apply(const vector<complex<T> >&
say i have the 3 non blocking sends like this MPI_Isend (); MPI_Isend ();
Say I have a higher kinded type SuperMap[Key[_],Value[_]]`. Suppose now that I had something
Say I have the following code: private Integer number; private final Object numberLock =

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.