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

The Archive Base Latest Questions

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

My question may be not very good formulated because I haven’t worked with MongoDB

  • 0

My question may be not very good formulated because I haven’t worked with MongoDB yet, so I’d want to know one thing.

I have an object (record/document/anything else) in my database – in global scope.

And have a really huge array of other objects in this object.

So, what about speed of search in global scope vs search “inside” object? Is it possible to index all “inner” records?

Thanks beforehand.

So, like this

users: {
..
user_maria:
{
  age: "18",
  best_comments :
    {
      goodnight:"23rr",
      sleeptired:"dsf3"
     ..
    }
}

user_ben:
{
  age: "18",
  best_comments :
    {
      one:"23rr",
      two:"dsf3"
     ..
    }
}

So, how can I make it fast to find user_maria->best_comments->goodnight (index context of collections “best_comment”) ?

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

    First of all, your example schema is very questionable. If you want to embed comments (which is a big if), you’d want to store them in an array for appropriate indexing. Also, post your schema in JSON format so we don’t have to parse the whole name/value thing :

    db.users {
        name:"maria",
        age: 18,
        best_comments: [
            {
                title: "goodnight",
                comment: "23rr"
            },
            {
                title: "sleeptired",
                comment: "dsf3"
            }
        ]
    }
    

    With that schema in mind you can put an index on name and best_comments.title for example like so :

    db.users.ensureIndex({name:1, 'best_comments.title:1})
    

    Then, when you want the query you mentioned, simply do

    db.users.find({name:"maria", 'best_comments.title':"first"})
    

    And the database will hit the index and will return this document very fast.

    Now, all that said. Your schema is very questionable. You mention you want to query specific comments but that requires either comments being in a seperate collection or you filtering the comments array app-side. Additionally having huge, ever growing embedded arrays in documents can become a problem. Documents have a 16mb limit and if document increase in size all the time mongo will have to continuously move them on disk.

    My advice :

    • Put comments in a seperate collection
    • Either do document per comment or make comment bucket documents (say,
      100 comments per document)
      Read up on Mongo/NoSQL schema design. You always query for root documents so if you end up needing a small part of a large embedded structure you need to reexamine your schema or you’ll be pumping huge documents over the connection and require app-side filtering.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may not be a programming question, but I don't know where to ask
This may not be the kind of question one should ask on StackOverflow, but
I think my question may be a duplicate, but I do not know what
This question might appear very simple, but i haven't found an answer yet, so
Ok, I know the answer for this question may not be objective but I
This question may not directly relate to programming. I have noticed that the technology
In advance, I apologize if the question title may not be be convenient. I'm
My question may be quite similar to others, but not the same. In the
I concede that this question may fall into the 'discussable' but not 'answerable' category.
Simple question, the answer may not be... I'm going to be developing a web

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.