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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:41:01+00:00 2026-06-11T18:41:01+00:00

I know that MongoDB uses async writes by default when inserting/updating/deleting documents. My question

  • 0

I know that MongoDB uses async writes by default when inserting/updating/deleting documents. My question is if these updates are still performed in order.

Let’s assume the following upsert-queries followed by a delete-query:

db.servers.update({ "server": "abcdef" }, { "$set": { "lastSeen": new Date()}}, /*upsert=*/ true);
db.servers.update({ "server": "uvwxyz" }, { "$set": { "lastSeen": new Date()}}, /*upsert=*/ true);
db.servers.remove({ "lastSeen": { "$lt": new Date(Date.now() - 3600000) }  });

If these comands are executed in these order, is then guaranteed (if the operations succeeds) that first the two documents are inserted/updated and then the delete operation will delete outdated documents? I want that the both inserted/deleted documents are not deleted because their “lastSeen”-value was updated.

I think the “async-write-thing” has only to do with the time at which data is written from RAM to Disc. I think it does not affect the order of the commands so that the example above will always work (if the updates succeed), right?

EDIT: I use a single mongod-instance. No replica-set, no sharding 🙂

  • 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-11T18:41:02+00:00Added an answer on June 11, 2026 at 6:41 pm

    Commands sent via single connection are serialized. So, if you do send those through one connection, it’s guaranteed that remove will happen after the two inserts.

    Async writes (AKA “fire and forget”) means that client library doesn’t wait for acknowledgement of the write. It just spits the insert into the socket and forgets about it. If, when applying this insert, there’s a unique index violation (for example), you’ll never know.

    By the way, you can use mongodb’s latest feature: TTL indexes! MongoDB will delete stale data on its own, you just keep inserting 🙂

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

Sidebar

Related Questions

I know that this sort of question has been asked here before, but still
I am newly starting on mongodb. I know that by default, mongodb pre allocated
I know that it is possible read and write data from mongodb via hadoop.
I have a Rails app that uses MySQL, MongoDB, NodeJS (and SocketIO). Right now,
I am very new to MongoDB. I know that MongoDB can replicate the nodes.
I'm learning MongoDB these days. I find that MongoDB doesn't support join. I just
I am considering using MongoDB to store documents that include a list of key/value
I know that if I create a connection to MongoDB in Java to a
I'm building a Django application that uses MongoDB and MongoEngine to store data. To
I know that objects in MongoDB can contain multiple levels of data (just the

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.