Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dhatawesomedude/0e52fe90b8c5d8367ee2 to your computer and use it in GitHub Desktop.

Select an option

Save dhatawesomedude/0e52fe90b8c5d8367ee2 to your computer and use it in GitHub Desktop.

Revisions

  1. @leommoore leommoore revised this gist May 29, 2014. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions mongodb_setting_up_a_replica_set.md
    Original file line number Diff line number Diff line change
    @@ -42,6 +42,8 @@ You need to connect to one of the database sets and setup the configuration. The


    ###Initialize the Replica Set
    The rs stands for replica set.

    rs.initiate(demoConfig)

    Please note that this can take some time to setup the databases initially. When it is complete it will return back:
    @@ -83,4 +85,10 @@ You may get an initial error ```error: { "$err" : "not master and slaveOk=false"

    You should then be able to access the data.

    ###Replica Set Status
    To check on the status of a replica set just use:

    rs.status()



  2. @leommoore leommoore revised this gist May 29, 2014. 1 changed file with 16 additions and 1 deletion.
    17 changes: 16 additions & 1 deletion mongodb_setting_up_a_replica_set.md
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,22 @@
    ###Configuration
    You need to connect to one of the database sets and setup the configuration. The mongo client is a javascript repl so you can do all the usual javascript commands.

    var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly: true}] };
    var demoConfig = {
    _id: "demo",
    members: [
    { _id: 0,
    host: 'localhost: 30000',
    priority: 10
    },
    { _id: 1,
    host: 'localhost: 40000'
    },
    { _id: 2,
    host: 'localhost: 50000',
    arbiterOnly: true
    }
    ]
    };


    ###Initialize the Replica Set
  3. @leommoore leommoore revised this gist May 29, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions mongodb_setting_up_a_replica_set.md
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,7 @@
    db.getMongo()

    ###Configuration
    You need to connect to one of the database sets and setup the configuration. The mongo client is a javascript repl so you can do all the usual javascript commands.

    var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly: true}] };

  4. @leommoore leommoore revised this gist Sep 28, 2013. 1 changed file with 30 additions and 1 deletion.
    31 changes: 30 additions & 1 deletion mongodb_setting_up_a_replica_set.md
    Original file line number Diff line number Diff line change
    @@ -38,4 +38,33 @@ Please note that this can take some time to setup the databases initially. When
    The prompt will change to ```demo:PRIMARY>```.

    ###Test
    To t
    To test add some data to the primary:

    db.foo.save({_id:1, value:'hello world'})

    Check that the data is saved on the primary:

    db.foo.find()

    This will return:

    { "_id" : 1, "value" : "hello world" }

    Then log onto the secondary. This will have a prompt of ```demo:SECONDARY>```.

    db.foo.find()

    This will return:

    { "_id" : 1, "value" : "hello world" }



    ####Error not master and slaveOk=false
    You may get an initial error ```error: { "$err" : "not master and slaveOk=false", "code" : 13435 }``` when you are trying to run ```db.foo.find()```. This is because the secondary (ie the Slave) is not setup to perform reads. This can be enabled using the following command:

    db.setSlaveOk()

    You should then be able to access the data.


  5. @leommoore leommoore revised this gist Sep 28, 2013. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion mongodb_setting_up_a_replica_set.md
    Original file line number Diff line number Diff line change
    @@ -26,4 +26,16 @@


    ###Initialize the Replica Set
    rs.initiate(demoConfig)
    rs.initiate(demoConfig)

    Please note that this can take some time to setup the databases initially. When it is complete it will return back:

    {
    "info" : "Config now saved locally. Should come online in about a minute.",
    "ok" : 1
    }

    The prompt will change to ```demo:PRIMARY>```.

    ###Test
    To t
  6. @leommoore leommoore revised this gist Sep 28, 2013. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions mongodb_setting_up_a_replica_set.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #MongoDB - Setting up a cluster
    #MongoDB - Setting up a Replica Set

    cd \mongodbdir\

    @@ -20,4 +20,10 @@

    db.getMongo()

    var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly: true}] };
    ###Configuration

    var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly: true}] };


    ###Initialize the Replica Set
    rs.initiate(demoConfig)
  7. @leommoore leommoore renamed this gist Sep 28, 2013. 1 changed file with 0 additions and 0 deletions.
  8. @leommoore leommoore revised this gist Sep 28, 2013. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions mongodb_setting_up_a_cluster.md
    Original file line number Diff line number Diff line change
    @@ -2,22 +2,22 @@

    cd \mongodbdir\

    md \\mongodbdir\db1
    md \\mongodbdir\db2
    md \\mongodbdir\db3
    mkdir db1
    mkdir db2
    mkdir db3

    ###Primary
    start "a" mongod --dbpath ./db1 --port 30000 --replSet "demo"
    mongod --dbpath ./db1 --port 30000 --replSet "demo"

    ###Secondary
    start "b" mongod --dbpath ./db2 --port 40000 --replSet "demo"
    mongod --dbpath ./db2 --port 40000 --replSet "demo"

    ###Arbiter
    start "c" mongod --dbpath ./db3 --port 50000 --replSet "demo"
    mongod --dbpath ./db3 --port 50000 --replSet "demo"


    mongo --port 3000

    db.getMongo()

    var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly}] };
    var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly: true}] };
  9. @leommoore leommoore revised this gist Sep 28, 2013. 1 changed file with 13 additions and 13 deletions.
    26 changes: 13 additions & 13 deletions mongodb_setting_up_a_cluster.md
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,23 @@
    #MongoDB - Setting up a cluster

    cd \mongodbdir\
    cd \mongodbdir\

    md \\mongodbdir\db1
    md \\mongodbdir\db2
    md \\mongodbdir\db3
    md \\mongodbdir\db1
    md \\mongodbdir\db2
    md \\mongodbdir\db3

    @REM Primary
    start "a" mongod --dbpath ./db1 --port 30000 --replSet "demo"
    ###Primary
    start "a" mongod --dbpath ./db1 --port 30000 --replSet "demo"

    @REM Secondary
    start "b" mongod --dbpath ./db2 --port 40000 --replSet "demo"
    ###Secondary
    start "b" mongod --dbpath ./db2 --port 40000 --replSet "demo"

    @REM Arbiter
    start "c" mongod --dbpath ./db3 --port 50000 --replSet "demo"
    ###Arbiter
    start "c" mongod --dbpath ./db3 --port 50000 --replSet "demo"


    mongo --port 3000
    mongo --port 3000

    db.getMongo()
    db.getMongo()

    var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly}] };
    var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly}] };
  10. @leommoore leommoore revised this gist Sep 28, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion mongodb_setting_up_a_cluster.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    cd \mongodbdir\
    #MongoDB - Setting up a cluster

    cd \mongodbdir\

    md \\mongodbdir\db1
    md \\mongodbdir\db2
    md \\mongodbdir\db3
  11. @leommoore leommoore created this gist Sep 28, 2013.
    22 changes: 22 additions & 0 deletions mongodb_setting_up_a_cluster.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    cd \mongodbdir\
    #MongoDB - Setting up a cluster

    md \\mongodbdir\db1
    md \\mongodbdir\db2
    md \\mongodbdir\db3

    @REM Primary
    start "a" mongod --dbpath ./db1 --port 30000 --replSet "demo"

    @REM Secondary
    start "b" mongod --dbpath ./db2 --port 40000 --replSet "demo"

    @REM Arbiter
    start "c" mongod --dbpath ./db3 --port 50000 --replSet "demo"


    mongo --port 3000

    db.getMongo()

    var demoConfig = { _id: "demo", members: [{ _id: 0, host: 'localhost: 30000', priority: 10},{ _id: 1, host: 'localhost: 40000'}, { _id: 2, host: 'localhost: 50000', arbiterOnly}] };