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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:06:09+00:00 2026-05-22T13:06:09+00:00

I am moving our messaging system to MongoDB and am curious what approach to

  • 0

I am moving our messaging system to MongoDB and am curious what approach to take with respect to various stats, like number of messages per user etc. In MS SQL database I have a table where I have different counts per user and they get updated by trigger on corresponding tables, so I can for example know how many unread messages UserA has without calling an expensive SELECT Count(*) operation.

Is count function in MongoDB also expensive?
I started reading about map/reduce but my site is high load, so statistics has to update in real time, and my understanding is that map/reduce is time consuming operation.

What would be the best (performance-wise) approach on gathering various aggregate counts in MongoDB?

  • 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-22T13:06:10+00:00Added an answer on May 22, 2026 at 1:06 pm

    If you’ve got a lot of data, then I’d stick with the same approach and increment an aggregate counter whenever a new message is added for a user, using a collection something like this:

    counts

    {
        userid: 123,
        messages: 10
    }
    

    Unfortunately (or fortunately?) there are no triggers in MongoDB, so you’d increment the counter from your application logic:

    db.counts.update( { userid: 123 }, { $inc: { messages: 1 } } )
    

    This’ll give you the best performance, and you’d probably also put an index on the userid field for fast lookups:

    db.counts.ensureIndex( { userid: 1 } )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our organization is moving towards a new case management system. One of the functions
I'd like to start moving our application business layers into a collection of REST
I am investigating moving our installer over to use InnoSetup and would like to
We are moving our mysql database to strict_all_tables from non-strict mode and would like
We are moving our projects to TFS 2010 using the SfTS v3 (Scrum for
We're in the process of moving our SQL Server to it's own machine, but
While evaluating the advantages and disadvantages of moving our Subversion-based repository over to Git,
I want my Views to move horizontally in tandem with our finger moving. Please
Our team is moving into much larger projects in size, many of which use
At our firm, we're experimenting with moving from svn to git. We want to

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.