Practical MongoDB by Shakuntala Gupta Edward & Navin Sabharwal

Practical MongoDB by Shakuntala Gupta Edward & Navin Sabharwal

Author:Shakuntala Gupta Edward & Navin Sabharwal
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA

If while specifying number the number is greater than the nodes that actually hold the data, the command will keep on waiting until the members are available. In order to avoid this indefinite wait time, wtimeout should also be used along with w, which will ensure that it will wait for the specified time period, and if the write has not succeeded by that time, it will time out.

How Writes Happen with Write Concern

In order to ensure that the written data is present on say at least two members, issue the following command :

>db.testprod.insert({i:”test”, q: 50, t: “B”}, {writeConcern: {w:2}})

In order to understand how this command will be executed, say you have two members, one named primary and the other named secondary, and it is syncing its data from the primary.

But how will the primary know the point at which the secondary is synced? Since the primary’s oplog is queried by the secondary for op results to be applied, if the secondary requests an op written at say t time, it implies to the primary that the secondary has replicated all ops written before t.

The following are the steps that a write concern takes. 1.The write operation is directed to the primary.


Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.