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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:30:35+00:00 2026-05-28T15:30:35+00:00

I have a question on designing index in MongoDB. Say i have a users

  • 0

I have a question on designing index in MongoDB.

Say i have a users collection and groups collection.

user {
name : "" ,
age :  19
}

group {
name : ""
members : [],
posts :  [ { date : "" , author : "" , topic : "" }, { date : "" ,
author : "" , topic : "" } ......]
}

There can be 1000’s of groups and each group can have millions of
posts. Operations I frequently perform is:

  1. getting posts based on date (70%)
  2. updating posts (30%)

So, essentially I need to index on date.

My question is:

Should i create a new posts collection like

posts {
name : "",  date : "" , author : "" , topic : ""
}

and create a single-value index on date in posts collection

( db.posts.ensureIndex({posts : 1}) )

OR

Should i include posts inside of group object and create an embedded
index like db.groups.ensureIndex({ posts.date : 1})

Which one is more efficient ? whats the best practice if this needs to
scale to millions of posts ?

Thanks

  • 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-28T15:30:36+00:00Added an answer on May 28, 2026 at 3:30 pm

    @Z5h, I think u mis-understood the problem.
    The problem was getting posts of a particular group between a date range.
    and storing them most effectively.

    and after some thinking and research, this’s what i found out.

    • First, there’s a limit on size of document ( currently 16MB ), and as post schema/posts increase in size, this may stop scaling some day as number of posts increase.and u cannot add an index to search within array of sub documents, as indexes are only across collections.

    • Second, If posts are stored as embedded sub documents, there would be no way to search within posts for a group in a date range. I have to get entire posts array and do processing on client side which is inefficient. There’s no way to compare array objects based on a field in sub document as of now. refer this

    • Hence better way is to create a separate posts collection , and have foll data

      posts{
      group_name : objectID(<ID in groups collection>),
      date : "",
      author : "",
      topic : "" 
      }
      

    By this way, i can as well create index on date and get all data for a group in a date range more effectively.

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

Sidebar

Related Questions

Well,i have a weird question to ask,sometimes when designing a form and using lots
I have what is most likely a very simple question.. I am designing a
I have a quick question regarding a database that I am designing and making
I'm designing a question-and-answer Ruby on Rails application. After a user logs in, you
I have a c# question that im struggling with. I am designing a class
I've been doing some reading into designing template code have a question about it.
I have a question about defining Foreign Key in EF Code First Fluent API.
I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I have

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.