close

Write Concern Reference

Write concern describes the guarantee that MongoDB provides when reporting on the success of a write operation.

 

 

Application 將資料寫到Mongodb,其實並沒有立即寫到Disk中而是寫到Memory 中。 紀錄或資料是在記憶體中待一會才被寫到Disk中。而在從記憶體到資料庫的這一段就叫 journal

2015-09-13_014332  

W option

W option provides the ability to disable write concern entirely as well as specify the write concern for replica sets.

 

MongoDB uses w : 1 as the default write concern w: 1 provide basic reciept acknowledgment

W選項是"應用程式"(你的code)對寫入資料的關心度MongoDB, W選項預設值是1,表示應用程式完全放心資料有寫到Disk,也可以說漠不關心啦!! 當資料寫到記憶體時,MongoDB就會回應給Application說我收到了。

2015-09-13_022915  

The w option accepts the following values:

ValueDescription
1

Provides acknowledgment of write operations on a standalone mongod or the primary in a replica set.

This is the default write concern for MongoDB.

0

Disables basic acknowledgment of write operations, but returns information about socket exceptions and networking errors to the application.

If you disable basic write operation acknowledgment but require journal commit acknowledgment, the journal commit prevails, and the server will require that mongodacknowledge the write operation.

<Number greater than 1>

Guarantees that write operations have propagated successfully to the specified number of replica set members including the primary.

For example, w: 2 indicates acknowledgements from the primary and at least one secondary.

If you set w to a number that is greater than the number of set members that hold data, MongoDB waits for the non-existent members to become available, which means MongoDB blocks indefinitely.

"majority"

Confirms that write operations have propagated to the majority of voting nodes: a majority of the replica set’s voting members must acknowledge the write operation before it succeeds. This allows you to avoid hard coding assumptions about the size of your replica set into your application.

Changed in version 3.0: In previous versions, w: "majority" refers to the majority of the replica set’s members.

Changed in version 2.6: In Master/Slave deployments, MongoDB treats w: "majority"as equivalent to w: 1. In earlier versions of MongoDB, w: "majority" produces an error in master/slave deployments.

<tag set> By specifying a tag set, you can have fine-grained control over which replica set members must acknowledge a write operation to satisfy the required level of write concern.

 

 

J Option

The j option confirm that the mongod instance has written the data to the on-disk journal. The ensures that data is not lost if the mongod instance shuts down unexpectedly. 

 

J 選項就是用來確認 MongoDB 有將資料寫到DISK才會回應給Application ,確認資料沒有丟失。預設值是0,使用時請設成1

 

Data source :http://docs.mongodb.org/manual/reference/write-concern/

 

 

 

arrow
arrow
    創作者介紹
    創作者 Kenneth 的頭像
    Kenneth

    Kenneth的部落格

    Kenneth 發表在 痞客邦 留言(0) 人氣()