Understanding the Write Concern

Before connecting to and updating data on a MongoDB server, you need to decide what level of write concern you want to implement on your connection. A write concern is the guarantee that the MongoDB connection provides when reporting on the success of a write operation. The strength of a write concern determines the level of guarantee.

The basic idea is that stronger write concerns tell MongoDB to wait until a write has successfully been written to disk before responding. On the other hand, a weaker write concern may only wait until MongoDB has successfully scheduled a change to be written before responding. The downside of stronger write concerns is that the stronger they are, the longer MongoDB waits to respond to the client connection, and thus write requests are a bit slower.

From a MongoDB driver connection perspective, the write concern can be set to one of the levels listed in Table 13.1. You set this level on the server connection, and it applies to all connections to the server. If a write error is detected, an error is returned in the callback function of the write request.

Image

Table 13.1 Write concern levels for MongoDB connections

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.164.34