How to configure a replica set with MongoDBHow to configure MongoDB Replica SetAdd Secondary to Replica Set in MongoDB WindowsHow to query MongoDB with “like”?How do I drop a MongoDB database from the command line?Replica Set Error Code 76MongoDB conf in absence of Arbiter to host election to choosing a primarymongo-connector error on ubuntu 14.14Can't convert standalone mongoDB to Replica Set: Connection timed outmongodb replication in sharded machineReplica - MongoDB EC2 instancesMongoDB Replica set with external addressesGetting error message while replication database in mongodb windows

PhD student with mental health issues and bad performance

Did Darth Vader wear the same suit for 20+ years?

Pros and cons of writing a book review?

Do I add my ability modifier to the damage of the bonus-action attack granted by the Crossbow Expert feat?

Should we freeze the number of people coming in to the study for Kaplan-Meier test

What if you don't bring your credit card or debit for incidentals?

Unconventional Opposites

Strange math syntax in old basic listing

Chopin: marche funèbre bar 15 impossible place

Computing the differentials in the Adams spectral sequence

How should I push back against my job assigning "homework"?

Is there a term for this?

Sucuri detects malware on wordpress but I can't find the malicious code

Incremental Ranges!

Explain Ant-Man's "not it" scene from Avengers: Endgame

Is having a hidden directory under /etc safe?

Could a guilty Boris Johnson be used to cancel Brexit?

Is it possible for people to live in the eye of a permanent hypercane?

Is the capacitor drawn or wired wrongly?

Humans meet a distant alien species. How do they standardize? - Units of Measure

Have powerful mythological heroes ever run away or been deeply afraid?

Hygienic footwear for prehensile feet?

How to decline physical affection from a child whose parents are pressuring them?

Is there a rule that prohibits us from using 2 possessives in a row?



How to configure a replica set with MongoDB


How to configure MongoDB Replica SetAdd Secondary to Replica Set in MongoDB WindowsHow to query MongoDB with “like”?How do I drop a MongoDB database from the command line?Replica Set Error Code 76MongoDB conf in absence of Arbiter to host election to choosing a primarymongo-connector error on ubuntu 14.14Can't convert standalone mongoDB to Replica Set: Connection timed outmongodb replication in sharded machineReplica - MongoDB EC2 instancesMongoDB Replica set with external addressesGetting error message while replication database in mongodb windows






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








6















I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.



Below you can see an overview of my goal.



I want configure Replication Set in MongoDB for that i tried like this



use local
db.dropDatabase()

config = _id: "rs0", members:[
_id: 0, host: 'localhost:27017']


rs.initiate(config)


i hope every thing is correct only but here its showing the following error message



 "errmsg" : "server is not running with --replSet", "ok" : 0 


Anything wrong i did here ?



Any ideas ?










share|improve this question



















  • 1





    the error message tells you exactly what you need to do: change your configuration file (usually /etc/mongodb.conf, depends on your Linux distribution), add this line: replSet = [replica set name]

    – yaoxing
    Apr 22 '14 at 5:02











  • @yaoxing still i'm getting same error message...

    – Naresh
    Apr 22 '14 at 5:08


















6















I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.



Below you can see an overview of my goal.



I want configure Replication Set in MongoDB for that i tried like this



use local
db.dropDatabase()

config = _id: "rs0", members:[
_id: 0, host: 'localhost:27017']


rs.initiate(config)


i hope every thing is correct only but here its showing the following error message



 "errmsg" : "server is not running with --replSet", "ok" : 0 


Anything wrong i did here ?



Any ideas ?










share|improve this question



















  • 1





    the error message tells you exactly what you need to do: change your configuration file (usually /etc/mongodb.conf, depends on your Linux distribution), add this line: replSet = [replica set name]

    – yaoxing
    Apr 22 '14 at 5:02











  • @yaoxing still i'm getting same error message...

    – Naresh
    Apr 22 '14 at 5:08














6












6








6


3






I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.



Below you can see an overview of my goal.



I want configure Replication Set in MongoDB for that i tried like this



use local
db.dropDatabase()

config = _id: "rs0", members:[
_id: 0, host: 'localhost:27017']


rs.initiate(config)


i hope every thing is correct only but here its showing the following error message



 "errmsg" : "server is not running with --replSet", "ok" : 0 


Anything wrong i did here ?



Any ideas ?










share|improve this question
















I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.



Below you can see an overview of my goal.



I want configure Replication Set in MongoDB for that i tried like this



use local
db.dropDatabase()

config = _id: "rs0", members:[
_id: 0, host: 'localhost:27017']


rs.initiate(config)


i hope every thing is correct only but here its showing the following error message



 "errmsg" : "server is not running with --replSet", "ok" : 0 


Anything wrong i did here ?



Any ideas ?







mongodb replication






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 22 '14 at 5:12









Neil Lunn

103k23186191




103k23186191










asked Apr 22 '14 at 4:48









NareshNaresh

3481828




3481828







  • 1





    the error message tells you exactly what you need to do: change your configuration file (usually /etc/mongodb.conf, depends on your Linux distribution), add this line: replSet = [replica set name]

    – yaoxing
    Apr 22 '14 at 5:02











  • @yaoxing still i'm getting same error message...

    – Naresh
    Apr 22 '14 at 5:08













  • 1





    the error message tells you exactly what you need to do: change your configuration file (usually /etc/mongodb.conf, depends on your Linux distribution), add this line: replSet = [replica set name]

    – yaoxing
    Apr 22 '14 at 5:02











  • @yaoxing still i'm getting same error message...

    – Naresh
    Apr 22 '14 at 5:08








1




1





the error message tells you exactly what you need to do: change your configuration file (usually /etc/mongodb.conf, depends on your Linux distribution), add this line: replSet = [replica set name]

– yaoxing
Apr 22 '14 at 5:02





the error message tells you exactly what you need to do: change your configuration file (usually /etc/mongodb.conf, depends on your Linux distribution), add this line: replSet = [replica set name]

– yaoxing
Apr 22 '14 at 5:02













@yaoxing still i'm getting same error message...

– Naresh
Apr 22 '14 at 5:08






@yaoxing still i'm getting same error message...

– Naresh
Apr 22 '14 at 5:08













2 Answers
2






active

oldest

votes


















9














You can actually follow the MongoDB Manual to setup your replica set. It's pretty clear.
Here are some critical steps described below:




  1. Change your configuration file and add the following line.Don't mess it up with master/slave replication, because replica set is meant to be a replacement of master/slave replication. So you may want to remove those master/slave related config from your configuration files.



    replSet = [set name]


    EDIT: The replSet does not seem to exist anymore in recent versions of mongoDB, at least it is no longer documented. The following seems to have done the trick in my case.



    replication: 
    replSetName: "smm"



  2. Restart your mongod instance:



    systemctl restart mongodb
    // or
    service mongod restart



  3. go to local database and initiate your replica set. Don't pass anything to the initiate function, and mongodb will handle everything just well. Note it will use your hostname as the name of current instance and as I know it's not that easy to change. So you may want to change your host name before doing so.



    use local
    rs.initiate()


That's it. Your set is good to go. If you have other member to join the set, you need to do the 1/2 steps, and go to your primary instance and type:



rs.add("hostname:port")


Only when you want to change configs of replica set, do you need to type:



var conf = rs.conf();
// change your conf here
rs.reconfig(conf);


Note this will lead to server offline a little bit time. If you are doing it online, be careful.






share|improve this answer

























  • near to rs.initiate() i'm getting same error message "errmsg" : "server is not running with --replSet", "ok" : 0

    – Naresh
    Apr 22 '14 at 5:19











  • & if i tried forcefully with rs.reconfig(conf) its giving the following err " TypeError: rs.conf() has no properties shell/utils.js:1494 "

    – Naresh
    Apr 22 '14 at 5:22












  • how did you start your mongod instance? with command or as a daemon?

    – yaoxing
    Apr 22 '14 at 5:22











  • if you are starting it with shell command, it should be something like: mongod --replSet rs0 --dbpath /var/lib/mongo/...

    – yaoxing
    Apr 22 '14 at 5:23











  • with command only i started...

    – Naresh
    Apr 22 '14 at 5:23


















1














I would wish to discuss the concept of replication and replica set in MongoDB.




How do we get availability and fault tolerance? And by that we mean if that node goes down, we want to still be able to use the system. And if the primary nodes goes down and we lose it entirely for some reason, let's say there's a lost between backups or a hardware damage making the system unusable. And so what we do to solve both those problems is we introduce replication.




A replica set refers to a set of mongod and mongo nodes that act together and all mirror each other in terms of data. There is one primary and the other nodes are secondaries. But, that selection is dynamic. And the data written to the primary will asynchronously replicate to the secondaries. The application and drivers stay connected to the primary and will and can only write to the primary. Say, if primary goes down, one of the secondaries will perform an election to elect a new primary. To elect a new primary, we have to have a strict majority of the original number of nodes. So, since the original number of nodes here was 3, we need 2 nodes to elect a new primary and that's the number we have. So, if one went down, then anyone else can become primary. And in that case, the app will connect to the primary for the rights, through the driver. All transparently.



Later if the down servers gets up, it will join the replica set as a secondary. And the minimum number of nodes is 3 - because if we have less than 3, then what would remain would not be a majority of that set of the original set. And so, there would be no way to elect the new primary. So, we would go with no primary, which means we could no longer take rights.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23210587%2fhow-to-configure-a-replica-set-with-mongodb%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    9














    You can actually follow the MongoDB Manual to setup your replica set. It's pretty clear.
    Here are some critical steps described below:




    1. Change your configuration file and add the following line.Don't mess it up with master/slave replication, because replica set is meant to be a replacement of master/slave replication. So you may want to remove those master/slave related config from your configuration files.



      replSet = [set name]


      EDIT: The replSet does not seem to exist anymore in recent versions of mongoDB, at least it is no longer documented. The following seems to have done the trick in my case.



      replication: 
      replSetName: "smm"



    2. Restart your mongod instance:



      systemctl restart mongodb
      // or
      service mongod restart



    3. go to local database and initiate your replica set. Don't pass anything to the initiate function, and mongodb will handle everything just well. Note it will use your hostname as the name of current instance and as I know it's not that easy to change. So you may want to change your host name before doing so.



      use local
      rs.initiate()


    That's it. Your set is good to go. If you have other member to join the set, you need to do the 1/2 steps, and go to your primary instance and type:



    rs.add("hostname:port")


    Only when you want to change configs of replica set, do you need to type:



    var conf = rs.conf();
    // change your conf here
    rs.reconfig(conf);


    Note this will lead to server offline a little bit time. If you are doing it online, be careful.






    share|improve this answer

























    • near to rs.initiate() i'm getting same error message "errmsg" : "server is not running with --replSet", "ok" : 0

      – Naresh
      Apr 22 '14 at 5:19











    • & if i tried forcefully with rs.reconfig(conf) its giving the following err " TypeError: rs.conf() has no properties shell/utils.js:1494 "

      – Naresh
      Apr 22 '14 at 5:22












    • how did you start your mongod instance? with command or as a daemon?

      – yaoxing
      Apr 22 '14 at 5:22











    • if you are starting it with shell command, it should be something like: mongod --replSet rs0 --dbpath /var/lib/mongo/...

      – yaoxing
      Apr 22 '14 at 5:23











    • with command only i started...

      – Naresh
      Apr 22 '14 at 5:23















    9














    You can actually follow the MongoDB Manual to setup your replica set. It's pretty clear.
    Here are some critical steps described below:




    1. Change your configuration file and add the following line.Don't mess it up with master/slave replication, because replica set is meant to be a replacement of master/slave replication. So you may want to remove those master/slave related config from your configuration files.



      replSet = [set name]


      EDIT: The replSet does not seem to exist anymore in recent versions of mongoDB, at least it is no longer documented. The following seems to have done the trick in my case.



      replication: 
      replSetName: "smm"



    2. Restart your mongod instance:



      systemctl restart mongodb
      // or
      service mongod restart



    3. go to local database and initiate your replica set. Don't pass anything to the initiate function, and mongodb will handle everything just well. Note it will use your hostname as the name of current instance and as I know it's not that easy to change. So you may want to change your host name before doing so.



      use local
      rs.initiate()


    That's it. Your set is good to go. If you have other member to join the set, you need to do the 1/2 steps, and go to your primary instance and type:



    rs.add("hostname:port")


    Only when you want to change configs of replica set, do you need to type:



    var conf = rs.conf();
    // change your conf here
    rs.reconfig(conf);


    Note this will lead to server offline a little bit time. If you are doing it online, be careful.






    share|improve this answer

























    • near to rs.initiate() i'm getting same error message "errmsg" : "server is not running with --replSet", "ok" : 0

      – Naresh
      Apr 22 '14 at 5:19











    • & if i tried forcefully with rs.reconfig(conf) its giving the following err " TypeError: rs.conf() has no properties shell/utils.js:1494 "

      – Naresh
      Apr 22 '14 at 5:22












    • how did you start your mongod instance? with command or as a daemon?

      – yaoxing
      Apr 22 '14 at 5:22











    • if you are starting it with shell command, it should be something like: mongod --replSet rs0 --dbpath /var/lib/mongo/...

      – yaoxing
      Apr 22 '14 at 5:23











    • with command only i started...

      – Naresh
      Apr 22 '14 at 5:23













    9












    9








    9







    You can actually follow the MongoDB Manual to setup your replica set. It's pretty clear.
    Here are some critical steps described below:




    1. Change your configuration file and add the following line.Don't mess it up with master/slave replication, because replica set is meant to be a replacement of master/slave replication. So you may want to remove those master/slave related config from your configuration files.



      replSet = [set name]


      EDIT: The replSet does not seem to exist anymore in recent versions of mongoDB, at least it is no longer documented. The following seems to have done the trick in my case.



      replication: 
      replSetName: "smm"



    2. Restart your mongod instance:



      systemctl restart mongodb
      // or
      service mongod restart



    3. go to local database and initiate your replica set. Don't pass anything to the initiate function, and mongodb will handle everything just well. Note it will use your hostname as the name of current instance and as I know it's not that easy to change. So you may want to change your host name before doing so.



      use local
      rs.initiate()


    That's it. Your set is good to go. If you have other member to join the set, you need to do the 1/2 steps, and go to your primary instance and type:



    rs.add("hostname:port")


    Only when you want to change configs of replica set, do you need to type:



    var conf = rs.conf();
    // change your conf here
    rs.reconfig(conf);


    Note this will lead to server offline a little bit time. If you are doing it online, be careful.






    share|improve this answer















    You can actually follow the MongoDB Manual to setup your replica set. It's pretty clear.
    Here are some critical steps described below:




    1. Change your configuration file and add the following line.Don't mess it up with master/slave replication, because replica set is meant to be a replacement of master/slave replication. So you may want to remove those master/slave related config from your configuration files.



      replSet = [set name]


      EDIT: The replSet does not seem to exist anymore in recent versions of mongoDB, at least it is no longer documented. The following seems to have done the trick in my case.



      replication: 
      replSetName: "smm"



    2. Restart your mongod instance:



      systemctl restart mongodb
      // or
      service mongod restart



    3. go to local database and initiate your replica set. Don't pass anything to the initiate function, and mongodb will handle everything just well. Note it will use your hostname as the name of current instance and as I know it's not that easy to change. So you may want to change your host name before doing so.



      use local
      rs.initiate()


    That's it. Your set is good to go. If you have other member to join the set, you need to do the 1/2 steps, and go to your primary instance and type:



    rs.add("hostname:port")


    Only when you want to change configs of replica set, do you need to type:



    var conf = rs.conf();
    // change your conf here
    rs.reconfig(conf);


    Note this will lead to server offline a little bit time. If you are doing it online, be careful.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 19 at 15:43









    toto_tico

    8,32034765




    8,32034765










    answered Apr 22 '14 at 5:14









    yaoxingyaoxing

    2,50321326




    2,50321326












    • near to rs.initiate() i'm getting same error message "errmsg" : "server is not running with --replSet", "ok" : 0

      – Naresh
      Apr 22 '14 at 5:19











    • & if i tried forcefully with rs.reconfig(conf) its giving the following err " TypeError: rs.conf() has no properties shell/utils.js:1494 "

      – Naresh
      Apr 22 '14 at 5:22












    • how did you start your mongod instance? with command or as a daemon?

      – yaoxing
      Apr 22 '14 at 5:22











    • if you are starting it with shell command, it should be something like: mongod --replSet rs0 --dbpath /var/lib/mongo/...

      – yaoxing
      Apr 22 '14 at 5:23











    • with command only i started...

      – Naresh
      Apr 22 '14 at 5:23

















    • near to rs.initiate() i'm getting same error message "errmsg" : "server is not running with --replSet", "ok" : 0

      – Naresh
      Apr 22 '14 at 5:19











    • & if i tried forcefully with rs.reconfig(conf) its giving the following err " TypeError: rs.conf() has no properties shell/utils.js:1494 "

      – Naresh
      Apr 22 '14 at 5:22












    • how did you start your mongod instance? with command or as a daemon?

      – yaoxing
      Apr 22 '14 at 5:22











    • if you are starting it with shell command, it should be something like: mongod --replSet rs0 --dbpath /var/lib/mongo/...

      – yaoxing
      Apr 22 '14 at 5:23











    • with command only i started...

      – Naresh
      Apr 22 '14 at 5:23
















    near to rs.initiate() i'm getting same error message "errmsg" : "server is not running with --replSet", "ok" : 0

    – Naresh
    Apr 22 '14 at 5:19





    near to rs.initiate() i'm getting same error message "errmsg" : "server is not running with --replSet", "ok" : 0

    – Naresh
    Apr 22 '14 at 5:19













    & if i tried forcefully with rs.reconfig(conf) its giving the following err " TypeError: rs.conf() has no properties shell/utils.js:1494 "

    – Naresh
    Apr 22 '14 at 5:22






    & if i tried forcefully with rs.reconfig(conf) its giving the following err " TypeError: rs.conf() has no properties shell/utils.js:1494 "

    – Naresh
    Apr 22 '14 at 5:22














    how did you start your mongod instance? with command or as a daemon?

    – yaoxing
    Apr 22 '14 at 5:22





    how did you start your mongod instance? with command or as a daemon?

    – yaoxing
    Apr 22 '14 at 5:22













    if you are starting it with shell command, it should be something like: mongod --replSet rs0 --dbpath /var/lib/mongo/...

    – yaoxing
    Apr 22 '14 at 5:23





    if you are starting it with shell command, it should be something like: mongod --replSet rs0 --dbpath /var/lib/mongo/...

    – yaoxing
    Apr 22 '14 at 5:23













    with command only i started...

    – Naresh
    Apr 22 '14 at 5:23





    with command only i started...

    – Naresh
    Apr 22 '14 at 5:23













    1














    I would wish to discuss the concept of replication and replica set in MongoDB.




    How do we get availability and fault tolerance? And by that we mean if that node goes down, we want to still be able to use the system. And if the primary nodes goes down and we lose it entirely for some reason, let's say there's a lost between backups or a hardware damage making the system unusable. And so what we do to solve both those problems is we introduce replication.




    A replica set refers to a set of mongod and mongo nodes that act together and all mirror each other in terms of data. There is one primary and the other nodes are secondaries. But, that selection is dynamic. And the data written to the primary will asynchronously replicate to the secondaries. The application and drivers stay connected to the primary and will and can only write to the primary. Say, if primary goes down, one of the secondaries will perform an election to elect a new primary. To elect a new primary, we have to have a strict majority of the original number of nodes. So, since the original number of nodes here was 3, we need 2 nodes to elect a new primary and that's the number we have. So, if one went down, then anyone else can become primary. And in that case, the app will connect to the primary for the rights, through the driver. All transparently.



    Later if the down servers gets up, it will join the replica set as a secondary. And the minimum number of nodes is 3 - because if we have less than 3, then what would remain would not be a majority of that set of the original set. And so, there would be no way to elect the new primary. So, we would go with no primary, which means we could no longer take rights.






    share|improve this answer



























      1














      I would wish to discuss the concept of replication and replica set in MongoDB.




      How do we get availability and fault tolerance? And by that we mean if that node goes down, we want to still be able to use the system. And if the primary nodes goes down and we lose it entirely for some reason, let's say there's a lost between backups or a hardware damage making the system unusable. And so what we do to solve both those problems is we introduce replication.




      A replica set refers to a set of mongod and mongo nodes that act together and all mirror each other in terms of data. There is one primary and the other nodes are secondaries. But, that selection is dynamic. And the data written to the primary will asynchronously replicate to the secondaries. The application and drivers stay connected to the primary and will and can only write to the primary. Say, if primary goes down, one of the secondaries will perform an election to elect a new primary. To elect a new primary, we have to have a strict majority of the original number of nodes. So, since the original number of nodes here was 3, we need 2 nodes to elect a new primary and that's the number we have. So, if one went down, then anyone else can become primary. And in that case, the app will connect to the primary for the rights, through the driver. All transparently.



      Later if the down servers gets up, it will join the replica set as a secondary. And the minimum number of nodes is 3 - because if we have less than 3, then what would remain would not be a majority of that set of the original set. And so, there would be no way to elect the new primary. So, we would go with no primary, which means we could no longer take rights.






      share|improve this answer

























        1












        1








        1







        I would wish to discuss the concept of replication and replica set in MongoDB.




        How do we get availability and fault tolerance? And by that we mean if that node goes down, we want to still be able to use the system. And if the primary nodes goes down and we lose it entirely for some reason, let's say there's a lost between backups or a hardware damage making the system unusable. And so what we do to solve both those problems is we introduce replication.




        A replica set refers to a set of mongod and mongo nodes that act together and all mirror each other in terms of data. There is one primary and the other nodes are secondaries. But, that selection is dynamic. And the data written to the primary will asynchronously replicate to the secondaries. The application and drivers stay connected to the primary and will and can only write to the primary. Say, if primary goes down, one of the secondaries will perform an election to elect a new primary. To elect a new primary, we have to have a strict majority of the original number of nodes. So, since the original number of nodes here was 3, we need 2 nodes to elect a new primary and that's the number we have. So, if one went down, then anyone else can become primary. And in that case, the app will connect to the primary for the rights, through the driver. All transparently.



        Later if the down servers gets up, it will join the replica set as a secondary. And the minimum number of nodes is 3 - because if we have less than 3, then what would remain would not be a majority of that set of the original set. And so, there would be no way to elect the new primary. So, we would go with no primary, which means we could no longer take rights.






        share|improve this answer













        I would wish to discuss the concept of replication and replica set in MongoDB.




        How do we get availability and fault tolerance? And by that we mean if that node goes down, we want to still be able to use the system. And if the primary nodes goes down and we lose it entirely for some reason, let's say there's a lost between backups or a hardware damage making the system unusable. And so what we do to solve both those problems is we introduce replication.




        A replica set refers to a set of mongod and mongo nodes that act together and all mirror each other in terms of data. There is one primary and the other nodes are secondaries. But, that selection is dynamic. And the data written to the primary will asynchronously replicate to the secondaries. The application and drivers stay connected to the primary and will and can only write to the primary. Say, if primary goes down, one of the secondaries will perform an election to elect a new primary. To elect a new primary, we have to have a strict majority of the original number of nodes. So, since the original number of nodes here was 3, we need 2 nodes to elect a new primary and that's the number we have. So, if one went down, then anyone else can become primary. And in that case, the app will connect to the primary for the rights, through the driver. All transparently.



        Later if the down servers gets up, it will join the replica set as a secondary. And the minimum number of nodes is 3 - because if we have less than 3, then what would remain would not be a majority of that set of the original set. And so, there would be no way to elect the new primary. So, we would go with no primary, which means we could no longer take rights.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 24 '16 at 14:30









        studentstudent

        12k978137




        12k978137



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23210587%2fhow-to-configure-a-replica-set-with-mongodb%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript