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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:01:58+00:00 2026-06-07T03:01:58+00:00

We have a system in which we want to maintain stats on large volumes

  • 0

We have a system in which we want to maintain stats on large volumes of logged information split into separate channels, each channel will have an overview document maintaining stats including Max and Min values for the Hours, Days, Months and Years in a cascaded fashion.

We could maintain a single document to hold the stats of a channel for a month, which would have a single Monthly Max/Min, 31 Daily Max/Mins with 24 Hourly max mins for each of the those days.

Using a document for counting using $inc is great for in place atomic updates ,a $max and $min on the update modifier would solve our problem but that’s unfortunately not available.

We can keep the max and min within the task processors and issues $set but that has issues with coordinating those over all of the task processors in the system (potentially on different machines), so we have decided to keep mongo as the main reference. Also the same stats might be being updated by two seperate tasks being run concurrently on different task processor instances.

So we are looking for comment/suggestions on the best solution (we won’t necessarily keep the raw data so post processing is not an option)

  1. Read, update & save each time we need to update?

  2. Use db Eval to execute JavaScript server side to update the max/man cascade by passing in just a single value?

  3. Is there another way?

Many thanks for your help.

  • 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-07T03:02:01+00:00Added an answer on June 7, 2026 at 3:02 am

    I think you’re looking for optimistic locking. You can ensure that updates are atomic by storing a version field in your documents. Consider the following example:

    {_id: xyz, version: 2, max: 10}
    

    First find the document:

    db.example.find({_id:xyz})
    

    Store the version number and determine (client-side) whether or not the max value needs to be updated. If so,

    db.example.update({id:xyz, version: 2}, {$set: {max: 12}, $inc: {version: 1}})
    

    This update will fail if the version has changed between the time that the query and the update took place, thereby preventing concurrency-related data corruption. You can use getLastError to determine if the update failed, and subsequently retry from step one.

    You should avoid db.eval() since this operation requires a global lock.

    Additional resources on optimistic locking can be found here:
    http://www.mongodb.org/display/DOCS/Atomic+Operations#AtomicOperations-%22UpdateifCurrent%22
    http://code.google.com/p/morphia/wiki/MongoNewsletterArticleDec2010

    MongoDB documentation on concurrency: http://www.mongodb.org/display/DOCS/How+does+concurrency+work

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

Sidebar

Related Questions

Currently we have a system which we paid for that pushes information into Excel
I have a system which breaks a large taks into small tasks using about
We have a system which is composed of few applications. Each application at certain
I have a system which defines repeating patterns of days. Each pattern has a
I have a system which is receiving log files from different places through http
I have a system which contains multiple applications connected together using JMS and Spring
I have a system which receives leads (they are piped in via email) and
I need suggestion about YAMI library . I have a system which receives Json
I have a remote embedded system which it is telnet-able. How can I download
I have a System.Data.DataTable which is populated by reading a CSV file which sets

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.