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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:41:32+00:00 2026-06-04T18:41:32+00:00

I was wandering what keep MongoDB faster. Having a few parent documents with big

  • 0

I was wandering what keep MongoDB faster. Having a few parent documents with big arrays of embedded documents inside of them or having a lot of parent documents with few embedded documents inside.

This question only regards querying speed. I’m not concerned with the amount of repeated information, unless you tell me that it influences the search speed. (I don’t know if MongoDb automatically indexes Id’s)

Example:

Having the following Entities with only an Id field each one:

  • Class (8 different classes )
  • Student ( 100 different students )

In order to associate students with classes, would I be taking most advantage of MongoDB’s speed if I:

  • Stored all Students in arrays, inside the classes they attend
  • Inside each student, I kept an array with the classes they attend.

This example is just an example. A real sittuation would involve thousands of documents.

  • 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-04T18:41:34+00:00Added an answer on June 4, 2026 at 6:41 pm

    I am going to search for specific students inside a given class.

    If so, you should have a Student collection, with a field set to the class (just the class id is maybe better than an embedded and duplicated class document).

    Otherwise, you will not be able to query for students properly:

    db.students.find ({ class: 'Math101', gender: 'f' , age: 22 })
    

    will work as expected, whereas storing the students inside the classes they attend

    { _id: 'Math101', student: [
         { name: 'Jim', age: 22 } , { name: 'Mary', age: 23 }
      ] }
    

    has (in addition to duplication) the problem that the query

    db.classes.find ( { _id: 'Math101', 'student.gender': 'f', 'student.age': 22 })
    

    will give you the Math class with all students, as long as there is at least one female student and at least one 22-year-old student in it (who could be male).

    You can only get a list of the main documents, and it will contain all embedded documents, unfiltered, see also this related question.

    I don’t know if MongoDb automatically indexes Id

    The only automatic index is the primary key _id of the “main” document. Any _id field of embedded documents is not automatically indexed, but you can create such an index manually.

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

Sidebar

Related Questions

This is from ActionScript 2.0 not a big one, but enough to keep me
I was wondering how can I keep my main parent category highlighted as when
I have html snippets and i was wondering where I should keep them... For
I'm just wondering what others do in this respect: Do you try to keep
I'll keep this short and simple. As part of PHP's mcrypt library there are
I need to loop over a list of objects, comparing them like this: 0
I keep a lot of settings in AppSettings, and I was wondering if it's
This may be impossible, but I was wondering if it was possible to keep
I've come up with several manual ways of doing this, but i keep wondering
I was wondering why do I keep getting an error and unable to return

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.