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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:30:18+00:00 2026-06-03T14:30:18+00:00

Schema: { name: String, available: Boolean, for: String } there are a: { name:

  • 0

Schema:

{
    name: String,
    available: Boolean,
    for: String
}

there are “a”:

{
    name: "a",
    available: true,
    for: ["b", "c"]
}

and “b”:

{
    name: "b",
    available: true,
    for: ["a", "b]
}

if I update a.available = false, I should update b.available = false at the same time.
how could I update two documents and make sure there would not has other process/thread getting “b” between the time when updating “a” and “b”.

  • 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-03T14:30:20+00:00Added an answer on June 3, 2026 at 2:30 pm

    MongoDB doesn’t support atomic transactions. So if you need to make the first update “undo itself” if the second update fails, then you’re out of luck.

    However, in some limited cases, MongoDB does support isolated updates. The update isn’t all or nothing, but MongoDB will guarantee that nobody else writes to the collection in the middle of your write.

    A couple of major caveats:

    • The documents must all be in the same collection
    • The updates must all be specified in one query

    Based on the example you’ve provided, your case might qualify.

    Here is the documentation describing an isolated update.

    Basically you’ll want to issue the an update similar to the following to atomically set “available” to false when name is either “a” or “b”:

    db.blah.update({"name": {"$in": ["a", "b"]}, "$atomic": 1}, {"available": false});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have same table name on different schema with different data
Here is a Doctrine schema: Device: columns: name: { type: string(60), } os_version_id: {
I have MongooseJS schema as follow: var UserSchema = new Schema({ name : String,
I trying to make a schema for the following xml. <root> <allow_any_name id=string> <required_tag_1>string</required_tag_1>
I have some Mongoose Models with geospacial indexes: var User = new Schema({ name
Schema: Users ID Name Password Address ID Street UserID Both tables have an ID
I've models GuestOrder, OrderBatch, OrderItem # == Schema Information # # Table name: guest_orders
I have a database schema where the convention for a foreign key's name is:
I want to create a schema with with a name passed by variable. Example:
I have a table which have schema like this id name 1 jack 2

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.