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

  • Home
  • SEARCH
  • 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 8067201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:12:58+00:00 2026-06-05T12:12:58+00:00

From the MongoDB Update documentation they talk about the update operators being atomic. If

  • 0

From the MongoDB Update documentation they talk about the update operators being atomic. If the below query is called five times at the same instant and Zugwalt’s reputation starts at zero, I’d expect at the end for the reputation to be 5:

db.rep.update({_id: "Zugwalt"}, {$inc: {reputation: 1}});

However what if the update query is this?

db.rep.update({_id: "Zugwalt", reputation: {$lte: 3}}, {$inc: {reputation: 1}});

Would the reputation always only be updated three times or is there some weird race conditions where it could be more?

My particular case is using an active user to “claim a document”. I execute a query similar to:

db.myCollection.update({_id: "doc_id", activeUser: {$exists: false}}, {$set: {activeUser: "Zugwalt"}});

Ideally if this query fires multiple times at the same instance only one update will result in the collection being modified. However If the search component isn’t atomic with the update I could see a race condition where its first updated to set the activeUser to one user, and then immediately to another.

Side note: it seems more clear that the findAndModify command has this kind of atomicness, however I don’t want to use it as in our empirical testing with our node-js driver it seems much slower overall under heavy load.

  • 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-05T12:12:59+00:00Added an answer on June 5, 2026 at 12:12 pm

    In MongoDB updates are atomic. If you don’t need to get the document back, you don’t need to use findAndModify.

    In the scenarios you give, the expected thing will happen – in the first case reputation will end up as 5, in the second it’ll be 4.

    In your case only one update will successfully set activeUser.

    Here is a link that discusses atomic operations in MongoDB.

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

Sidebar

Related Questions

From the MongoDB command line I can do db.user.update({userid: {$in: [435707147,88513850,466518582]}},{$unset: {f1 : 1}})
From the C# documentation: The Save method is a combination of Insert and Update.
How do I update a mongodb collection from JS? db.collection('fruits', function (err, collection) {
I'm running an update on my MongoDB from Python. I have this line: self.word_counts[source].update({'date':posttime},{$inc
I lovely update a document with values(Maps coord) from clienside (under privileges). MongoDB use
I am using MongoDB with C# driver. I managed to add/delete/update data from collections,
From the documentation I read you can do this: db.people.update( { name:Joe }, {
I have a very large MongoDB object, about 2MB. I have to update frequently
I'm calling collection update from ruby driver to mongodb and gets a return code
How can you drop a numeric collection from MongoDB? PRIMARY> db.123456789011.remove({}); Tue Mar 20

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.