MONGODB official Website Document Read Note: write concern

Source: Internet
Author: User

Write concern guarantees the level of MongoDB write operations, and different write concern settings correspond to different levels of writes. The higher the level you set. The better the performance of the write operation is, the worse the write performance will be.

MongoDB default use ? The write concern level of acknowledged, which is also the highest level of security.

In the ? acknowledged-level replica set mode. MongoDB can set a wtimeout value on the client. Assuming that the write operation fails to complete within the specified time, it returns an error, even though it may finally be complete.

Write Concern Levels

unacknowledged

In unacknowledged mode, Mongodbserver does not confirm that the write operation is actually received, similar to ignoring the operation. However, the drive will still try to receive and process errors from the network, depending on the network configuration of the system. is a schematic of the unacknowledged level.


AcknowledgedIn acknowledged mode, Mongod will confirm that it received the write operation and apply the write to the in-memory data. Acknowledged? Mode execution client captures all network errors. Primary key conflicts, and other errors.

But acknowledged? There is no guarantee that write operations are applied to disk data. Here is the schematic diagram
journaledjournaled mode. Mongodbserver will confirm that the write is submitted to the journal log. So this level ensures that MongoDB can recover all the data after an unplanned outage.

Of course, this level must ensure that you open the journaling on the server side . And each time you have to wait until the next journal Log commits, you can try to increase the commit frequency of the journal log.

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center "/>
Replica acknowledged assuming your mongodb uses a replica set, the write operation may require additional consideration, and the default setting requires only the acknowledged of the master node . And in Replica acknowledged mode. It will ensure that all writes are applied to all nodes in the replica set, except that the journal log here only needs to ensure that the journal log commit of the master node is available.

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center "/>

Available write concern after each write operation, driver will invoke it on its own initiative.The GetLastError () command infers whether a write error has occurred and whether it is executed after the Writeconcern set, such as Db.runcommand ({getlasterror:1, w:2,j:true, wtimeout:5000}) is to confirm that the last operation W is 2,j for True,wtimeout 5000, there is no error. Db.things.insert ({dd:123},{writeconcern:{w:2}}) is the Writeconcern that sets the currently inserted SQL. db.setwriteconcern ({w:1,wtimeout:3000,j:1}) is the Writeconcern value that sets the current DB;
? Db.getwriteconcern () is the write concern setting for the current DB;

W? Option1 the default configuration to ensure that the primary node in a single instance mongod or replica set acknowled 0 all have no acknowled, but at this point you assume that the journal Commit?acknowled mode n first N>1,n value indicates the need to acknowled number of nodes majority ensure that most of the nodes in the replica set Span style= "Color:rgb (73,71,71); Font-family:akzidenz, ' Helvetica Neue ', Helvetica, Arial, sans-serif;font-size:14px; line-height:24px; " >acknowled
<tag set> guarantees that all nodes of this target replica set acknowled J? The OPTIONJ operation ensures that the data for the write operation is applied to the journal log on the disk, the value True indicates on, and the flase indicates off. Setting the replica set to true only guarantees that the write operation on the primary node is applied to the disk's journal log.WtimeoutThis value is only valid for cases where the value of W is set to greater than 1, which is only valid for the replica set environment. An error is returned when a time-out occurs, even if the data write is finally successful. MongoDB does not roll back data that has changed successfully.

Setting this value to 0 is not a limit.




MongoDB Official Document Read Note: Write concern

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.