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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:19:48+00:00 2026-06-16T07:19:48+00:00

For example I have models User and Post User { _id: ObjectId(pretendThisIsAUserObjectId), name: someUser

  • 0

For example I have models User and Post

User

{
    "_id": ObjectId("pretendThisIsAUserObjectId"),
    "name": "someUser"
}

Post

{
    "_id": ObjectId("pretendThisIsAUserObjectId"),
    "title": "blah blah",
    "user_id": ObjectId("pretendThisIsAUserObjectId"),
    "content": "more blah"
}

User has many posts. So we have user_id stored in Post.

So when we are listing posts for each user, we will have N+1 queries (N posts plus 1 query for user’s name), since we don’t have join in MongoDB.

Can we also store user name in Post, to optimize?

  • 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-16T07:19:49+00:00Added an answer on June 16, 2026 at 7:19 am

    The short answer is yes. You can denormalise your data to whatever extent you feel is appropriate for your particular needs. You could even go as far to storing an entire User document in each Post, but that would be a silly amount of duplication.

    My first inclination, however, would be to consider application-side caching of the username associated with each user ID, rather than trying to include the name in the Post document or querying for it each and every time you want it.

    If your usernames are unique, you could consider making the username the _id of your User document, rather than the standard ObjectId. That makes your user IDs even more useful as you no longer need to do additional queries to find the name of each user, because their name is their ID.

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

Sidebar

Related Questions

I have some rails app. For example I have next models: User , Post
I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
I have a model: class Example(models.Model): unique_hash = models.CharField(max_length=32,unique=True) content = models.FileField(upload_to='source',blank=True,verbose_name=HTML Content File)
I have a rails app which currently has 3 models: Post , User and
I have the models User, Post, Comment and Tag. User creates Post. Posts can
I have a parent model that has many child models, for example: App.Blog =
I have 3 model, User, Post, Comment with definition like below class Post <
I have two models, User and TrainingSession: class User < ActiveRecord::Base has_many :training_sessions end
Using the MVC pattern, is the following acceptable? User browses to www.example.com/blog/post/4 4 validates
I have a form that creates a new brand. The user chooses a name,

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.