InterviewSolution
| 1. |
Multiple addresses are stored as an embedded document for a user. Within the UI, each of these addresses need to be shown as an individual document along with all the user details. Should this be done programmatically? Or is there a simpler way to achieve this in MongoDB? |
|
Answer» Suppose we have 3 servers abc.com,xyz.com andpqr.com.
option –replset is used for creating a replica set. We have given a replica set NAME as rs0. Bind IP is the IP to which SERVER can be connected to from outside.
Login to server abc.com and run command mongo> it will take you to mongo shell. Now we need to initiate the replica set with a configuration of all 3 MEMBERS. rs.initiate( { _id : "rs0", members: [ { _id: 0, host: "abc.com:27017" }, { _id: 1, host: "xyz.com:27017" }, { _id: 2, host: "pqr.com:27017" } })MongoDB initiates a replica set, using the default replica set configuration.
rs.conf() Also to check the status for each member we can run command rs.status() The server from which we run rs.initiate will become primary and other 2 servers will become secondary. |
|