conf = rs.conf() 

2. Add tags to the replica set members reflecting their locations: 

conf.members[0].tags = { "dc.va": "rack1"} conf.members[1].tags = { "dc.va": "rack2"} conf.members[2].tags = { "dc.gto": "rack1"} conf.members[3].tags = { "dc.gto": "rack2"} conf.members[4].tags = { "dc.va": "rack1"} rs.reconfig(conf) 

3. Create a custom getLastErrorModes setting to ensure that the write operation will propagate to at least one member of each facility: 

conf.settings = { getLastErrorModes: { MultipleDC : { "dc.va": 1, "dc.gto": 1 } } } 

4. Reconfigure the replica set using the modified conf configuration object: 

rs.reconfig(conf) 

To ensure that a write operation propagates to at least one member of the set in both data centers, use the MultipleDC write concern mode as follows: 

db.users.insert( { id: "xyz", status: "A" }, { writeConcern: { w: "MultipleDC" } } ) 

Alternatively, if you want to ensure that each write operation propagates to at least 2 racks in each facility, reconfigure the replica set as follows in the mongo shell: 

1. Create a replica set configuration object conf : 

conf = rs.conf() 

2. Redefine the getLastErrorModes value to require two different values of both dc.va and dc.gto : 

conf.settings = { getLastErrorModes: { MultipleDC : { "dc.va": 2, "dc.gto": 2}} 

3. Reconfigure the replica set using the modified conf configuration object: 

rs.reconfig(conf) 

Now, the following write operation will only return after the write operation propagates to at least two different racks in the each facility: 

Changed in version 2.6: A new protocol for write operations (page 852) integrates write concerns with the write operations. Previous versions used the getLastError command to specify the write concerns. 

db.users.insert( { id: "xyz", status: "A" }, { writeConcern: { w: "MultipleDC" } } ) 

## Configure Tag Sets for Functional Segregation of Read and Write Operations 

Given a replica set with tag sets that reflect: 

• data center facility, 

• physical rack location of instance, and 

• storage system (i.e. disk) type. 

Where each member of the set has a tag set that resembles one of the following: 20 

