What is Write Concern in MongoDB?
Join the DZone community and get the full member experience.Join For Free
MongoDB provides different levels of write concern to better address the specific needs of applications. Clients may adjust write concern to ensure that the most important operations persist successfully to an entire MongoDB deployment. For other less critical operations, clients can adjust the write concern to ensure faster performance rather than ensure persistence to the entire deployment.
Write Concern LevelsMongoDB has the following levels of conceptual write concern, listed from weakest to strongest:
With an unacknowledged write concern, MongoDB does not acknowledge the receipt of write operations. Unacknowledged is similar to errors ignored; however, drivers will attempt to receive and handle network errors when possible. The driver’s ability to detect network errors depends on the system’s networking configuration.
With a receipt acknowledged write concern, the mongod confirms the receipt of the write operation. Acknowledged write concern allows clients to catch network, duplicate key, and other errors. This is default write concern.
With a journaled write concern, the MongoDB acknowledges the write operation only after committing the data to the journal. This write concern ensures that MongoDB can recover the data following a shutdown or power interruption.
You must have journaling enabled to use this write concern.
Replica sets present additional considerations with regards to write concern. The default write concern only requires acknowledgement from the primary. With replica acknowledged write concern, you can guarantee that the write operation propagates to additional members of the replica set.
Published at DZone with permission of Rishav Rohit, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Building and Deploying Microservices With Spring Boot and Docker
Redefining DevOps: The Transformative Power of Containerization
Cypress Tutorial: A Comprehensive Guide With Examples and Best Practices
A Data-Driven Approach to Application Modernization