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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:46:11+00:00 2026-05-21T19:46:11+00:00

I have this schema for support of in-site messaging: When I send a message

  • 0

I have this schema for support of in-site messaging:
enter image description here

When I send a message to another member, the message is saved to Message table; a record is added to MessageSent table and a record per recipient is added to MessageInbox table. MessageCount is being used to keep track of number of messages in the inbox/send folders and is filled using insert/delete triggers on MessageInbox/MessageSent – this way I can always know how many messages a member has without making an expensive “select count(*)” query.

Also, when I query member’s messages, I join to Member table to get member’s FirstName/LastName.

Now, I will be moving the application to MongoDB, and I’m not quite sure what should be the collection schema. Because there are no joins available in MongoDB, I have to completely denormalize it, so I woudl have MessageInbox, MessageDraft and MessageSent collections with full message information, right?

Then I’m not sure about following:

  1. What if a user changes his First/LastName? It will be stored denormalized as sender in some messages, as a part of Recipients in other messages – how do I update it in optimal ways?

  2. How do I get message counts? There will be tons of requests at the same time, so it has to be performing well.

Any ideas, comments and suggestions are highly appreciated!

  • 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-21T19:46:11+00:00Added an answer on May 21, 2026 at 7:46 pm

    I can offer you some insight as to what I have done to simulate JOINs in MongoDB.

    In cases like this, I store the ID of a corresponding user (or multiple users) in a given object, such as your message object in the messages collection.

    (Im not suggesting this be your schema, just using it as an example of my approach)

    {
        _id: "msg1234",
        from: "user1234",
        to: "user5678",
        subject: "This is the subject",
        body: "This is the body"
    } 
    

    I would query the database to get all the messages I need then in my application I would iterate the results and build an array of user IDs. I would filter this array to be unique and then query the database a second time using the $in operator to find any user in the given array.

    Then in my application, I would join the results back to the object.

    It requires two queries to the database (or potentially more if you want to join other collections) but this illustrates something that many people have been advocating for a long time: Do your JOINs in your application layer. Let the database spend its time querying data, not processing it. You can probably scale your application servers quicker and cheaper than your database anyway.

    I am using this pattern to create real time activity feeds in my application and it works flawlessly and fast. I prefer this to denormalizing things that could change like user information because when writing to the database, MongoDB may need to re-write the entire object if the new data doesnt fit in the old data’s place. If I needed to rewrite hundreds (or thousands) of activity items in my database, then it would be a disaster.

    Additionally, writes on MongoDB are blocking so if a scenario like I’ve just described were to happen, all reads and writes would be blocked until the write operation is complete. I believe this is scheduled to be addressed in some capacity for the 2.x series but its still not going to be perfect.

    Indexed queries, on the other hand, are super fast, even if you need to do two of them to get the data.

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

Sidebar

Related Questions

I have this schema: There is a table for persons. Each person has one
Say I have this table schema. ID AccNo Amount Say I have this data
I have a table which have schema like this id name 1 jack 2
i have this schema: <div id=container> <div id=content>some text</div> <footer> my footer things </footer>
I have this schema: <xs:complexType name=foo> <xs:sequence> <xs:element name=oneBar type=xs:string minOccurs=0/> <xs:element name=twoBar type=xs:string
I have this schema which I need to match 2 rows from user_data :
I have this in my schema: create_table robots_matches, :force => true do |t| t.integer
I have this problem decomposing a relation schema into a set of schemas that
I have this big doubt. When ever i use base64Binary in an .xsd schema
I have a schema like this <h1> 5/2009 <br/> Question: This is the question

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.