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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:32:50+00:00 2026-06-01T16:32:50+00:00

MongoDB has support for atomic updates. I.e. I can be sure that when a

  • 0

MongoDB has support for atomic updates. I.e. I can be sure that when a document is updated no other update will overwrite my previous change. My question relates to the combination of query and update statement, and is best illustrated by the example shown below.

db.foo.update(
{ state : 1, players: { $size: 2 } } , 
{ $push: { players : { new player document } } }, 
false , true );

In the above example, I only want to push a new player into a collection of players, if the number of players equals 2. Given the above query and update statement, is it possible that two simultaneous updates both push a player onto the same document, because at the time of reading the document its players $size is 2? I.e. does the atomicity span across the query and update part of the update statement or not?

Edit More in-depth sequence of events:

Consider firing the same update twice (U1 and U2) at the same time. Is the following sequence of events possible or not?

  1. U1 finds that document #1 matches the query portion of the update
    statement.
  2. U2 finds that document #1 matches the query portion of
    the update statement.
  3. U1 pushes a new player in document #1.
  4. U2 pushes a new player in document #1.

The end result is that document #1 contains one more player than expected, because both U1 and U2 were under the impression that document #1 contains only two players.

  • 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-01T16:32:52+00:00Added an answer on June 1, 2026 at 4:32 pm

    I’ve asked this question on the mongodb-user group. http://groups.google.com/group/mongodb-user/browse_thread/thread/e61e220dc0f6f64c

    According to the answer by Marc (who works at 10gen) the situation described by me cannot occur.

    The situation that you described is not possible; there is no danger
    of both updates modifying the same document.

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

Sidebar

Related Questions

Does MongoDB support multiple document update if selector (first argument) is selecting more than
I have a collection of articles in MongoDB that has the following structure: {
I have a hosted web application that has MongoDB as its DB. Now, I
I am using 10Gen .net driver for MongoDB and querying objects that has empty
I'm using MongoDB to hold a collection of documents. Each document has an _id
created a collection in MongoDB consisting of 11446615 documents. Each document has the following
MongoDB's ObjectId has a getTimestamp() method that returns time when the record was inserted.
I have an object that has an instance of Doctrine\ODM\MongoDB\Query\Builder . When I serialize
I have a simple project that has one submodule. $ git submodule 964737623a362f6303e87ec41f2c7090c8c2c093 lib/mongodb-php-odm
today I updated my Mongo.. mongodb-stable (from 10gen repo) but my service has down.

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.