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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:06:43+00:00 2026-05-21T09:06:43+00:00

I currently have some code which needs to perform multiple updates per user for

  • 0

I currently have some code which needs to perform multiple updates per user for thousands of users, incrementing a counter depending on an action they’ve taken in order to track what actions are being performed. Each action consists of subactions which need to have the count updated too. These need to be tracked by day.

So I am storing “action”:”actionName”, “day”:day, “count”: count, for actions per day (e.g. incoming from outside web page, start game, stop game by exiting, concatenated with the game name for a lot of games).

Each day I get a few thousand rows (one per unique action) added which are updated a few hundred thousand times each day to increase the count.

The relevant code is as follows (creating array of actions not included).

$m = new Mongo();
$db = $m->actionsDB;
$collection = $db->action_count;

foreach ($arr as $action) {
    $collection->update(array("action" => $action, "day" => $day),array('$inc' => array("count" => 1)),array("upsert" => true));)
}
$collection->ensureIndex(array("action" => 1, "day" => -1));

An example of the series of updates made on an action and subactions would be:
startGame, 20110417;
startGameZork, 20110417;
startGameZorkWindows, 20110417

The problem seems to be that with this code running on the server, mongo commands in the shell get queued up.

Currently I’m unsure as to why, I guess there may be a performance issue with so many updates per second.

What I am wondering is how can I increase performance? I’m pretty new to mongo, so not entirely sure what options are available. I looked at PHP’s batchInsert but I can’t see any mention of doing batchUpdate (so instead of updating, creating an array holding all the data I currently update then doing a batchUpdate in a single trip to the DB).

Mongo driver version is 1.2.0, so persistent connections are by default.

Edit: db.serverStatus() before, during and after on ~1600 updates per second (30 seconds). Test Data

  • 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-21T09:06:43+00:00Added an answer on May 21, 2026 at 9:06 am

    There is no built-in batching for updates/upserts. You can only limit the docs to be updated by adjusting your query expression and adding some further filter for “emulating” a batch somehow. MongoDB won’t help you here. Updates/Upserts are one or all.

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

Sidebar

Related Questions

I currently have some code that pulls down a list of users in a
I currently have some code that will produce a crash dump when my application
I've been trying to implement unit testing and currently have some code that does
Currently, I have some basic code to play a simple tone whenever a button
I'm tinkering with Silverlight 2.0. I have some images, which I currently have a
I have some Python code that works correctly when I use python.exe to run
I currently have a SQL Server (Express 2005) database to hold some transaction/metadata that
I currently use Strawberry Perl as my primary Perl distribution. However, I have some
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I have a challenge I need some input on. I am currently recruiting programmers

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.