0

I have setup a 3 node replica set.

Writing to primary node works but when I read with readPreference=secondary; I get values as null.

When I open the local node with robomongo I see that the collection does not exist. So it has not been replicated?

I am not sure when it gets replicated or am I missing something?

I have used the following URI

'mongodb://DNS1,DNS2,DNS3/?readPreference=secondary&w=0'

Update

Here is how my rs.status looks like

rs0:PRIMARY> rs.status()
{
    "set" : "rs0",
    "date" : ISODate("2014-03-10T10:57:13Z"),
    "myState" : 1,
    "members" : [
            {
                    "_id" : 0,
                    "name" : "NWI47:27017",
                    "health" : 1,
                    "state" : 1,
                    "stateStr" : "PRIMARY",
                    "uptime" : 16593,
                    "optime" : Timestamp(1394432703, 1),
                    "optimeDate" : ISODate("2014-03-10T06:25:03Z"),
                    "self" : true
            },
            {
                    "_id" : 1,
                    "name" : "t-plat-mongodb1.paand.local:27017",
                    "health" : 1,
                    "state" : 2,
                    "stateStr" : "SECONDARY",
                    "uptime" : 1656,
                    "optime" : Timestamp(1394432703, 1),
                    "optimeDate" : ISODate("2014-03-10T06:25:03Z"),
                    "lastHeartbeat" : ISODate("2014-03-10T10:57:13Z"),
                    "lastHeartbeatRecv" : ISODate("2014-03-10T10:57:11Z"),
                    "pingMs" : 187,
                    "syncingTo" : "NWI47:27017"
            },
            {
                    "_id" : 2,
                    "name" : "NWI27.np.i:27017",
                    "health" : 1,
                    "state" : 2,
                    "stateStr" : "SECONDARY",
                    "uptime" : 1664,
                    "optime" : Timestamp(1394432703, 1),
                    "optimeDate" : ISODate("2014-03-10T06:25:03Z"),
                    "lastHeartbeat" : ISODate("2014-03-10T10:57:11Z"),
                    "lastHeartbeatRecv" : ISODate("2014-03-10T10:57:12Z"),
                    "pingMs" : 102,
                    "syncingTo" : "NWI47:27017"
            }
    ],
    "ok" : 1

}

  • Contrary to what Garreth is saying, replication is not instantaneous. However your setup seems to be more or less ok. Are the server on the same LAN or are they far away ? How did you "register" the replica set ? On the slaves, rs.status, should show "syncingTo" attributes. Also rs.conf() should give you hostname that are actually reachable view TCP. Be careful, mongoDB is very sensitive to LAN/DNS conherence. – Oct Mar 10 '14 at 15:51
  • Yes the systems are at diff geographical location but in same domain. Yes the rs.config() which I have pasted has items with _id 1 & 2 which has the syncingTo attribute. What else could be the reason of not getting replicated. – Sherry Mar 10 '14 at 17:00
  • And does "NWI47" resolve to the correct "public" IP of the machine wherever your resolve the host (except on NWI47) ? There's no FW between the machines ? (does they see each other in full-IP ?) – Oct Mar 10 '14 at 17:02
  • Hmm how can I check that? Its in the same domain and are able to connect to each other; I could see that in the mongo log message which gets generated when mongo instance is running on the console. – Sherry Mar 10 '14 at 17:08
  • 1
    ok figured it out the problem. I was actually writing data to the 'local' database and which does not get replicated. So I created a new db with dif name and then it works like charm. Thank you very much for your contribution :) – Sherry Mar 11 '14 at 7:31
0

Mongo syncs instantly, so there is something wrong with your Replica set.

MongoDB replica sets are something that you need to get right from when they are first set up. If they aren't set up correctly, they can be difficult to fix.

Configuration of the Replica Set should (normally) be done from the master only. If your Set isn't live yet, the best option may be to re-create it.

Also, not sure what robomongo is, but you're probably better off using the native mongo client to find out what is going on.

The rs.status() command should give you output like this

rs0:SECONDARY> rs.status()
{
"set" : "rs0",
"date" : ISODate("2014-03-10T10:42:27Z"),
"myState" : 2,
"syncingTo" : "mongo-master:27017",
"members" : [
    {
        "_id" : 0,
        "name" : "mongo-master:27017",
        "health" : 1,
        "state" : 1,
        "stateStr" : "PRIMARY",
        "uptime" : 3008469,
        "optime" : Timestamp(1394448146, 1),
        "optimeDate" : ISODate("2014-03-10T10:42:26Z"),
        "lastHeartbeat" : ISODate("2014-03-10T10:42:26Z"),
        "lastHeartbeatRecv" : ISODate("2014-03-10T10:42:26Z"),
        "pingMs" : 1
    },
    {
        "_id" : 3,
        "name" : "mongo-slave3:27017",
        "health" : 1,
        "state" : 2,
        "stateStr" : "SECONDARY",
        "uptime" : 3012206,
        "optime" : Timestamp(1394448146, 1),
        "optimeDate" : ISODate("2014-03-10T10:42:26Z"),
        "self" : true
    },
    {
        "_id" : 4,
        "name" : "mongo-slave4:27017",
        "health" : 1,
        "state" : 2,
        "stateStr" : "SECONDARY",
        "uptime" : 890533,
        "optime" : Timestamp(1394448146, 1),
        "optimeDate" : ISODate("2014-03-10T10:42:26Z"),
        "lastHeartbeat" : ISODate("2014-03-10T10:42:26Z"),
        "lastHeartbeatRecv" : ISODate("2014-03-10T10:42:26Z"),
        "pingMs" : 0,
        "syncingTo" : "mongo-master:27017"
    }
],
"ok" : 1
}
  • I updated my question with the rs.status() I couldn't figure out the problem – Sherry Mar 10 '14 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.