# Failover MongoDB server

**URL:** <https://forums.rocket.chat/t/failover-mongodb-server/6404>\
**Category:** Community Support\
**Created:** [April 6, 2020, 12:27pm UTC](https://forums.rocket.chat/t/failover-mongodb-server/6404 "2020-04-06T12:27:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![djeantou](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@djeantou](https://forums.rocket.chat/u/djeantou)\
**Post date:** [April 6, 2020, 12:27pm UTC](https://forums.rocket.chat/t/failover-mongodb-server/6404/1 "2020-04-06T12:27:51Z")

</div>

Hi,

I am trying to setup rocketchat with multiple databases. I am using version 2.4.11 in a docker container with the following envs:

```
- MONGO_URL=mongodb://mongo1:27017/rocketchat?replSet=rs01,mongo2:27017/rocketchat?replSet=rs01&readPreference=primaryPreferred&w=majority
- MONGO_OPLOG_URL=mongodb://mongo1:27017/local?replSet=rs01,mongo2:27017/local?replSet=rs01

```

But I am receiving the following error:  
TypeError: Cannot read property ‘indexOf’ of undefined  
at parseQueryStringItemValue (/app/bundle/programs/server/npm/node\_modules/meteor/npm-mongo/node\_modules/mongodb-core/lib/uri\_parser.js:131:20)  
at value.split.reduce (/app/bundle/programs/server/npm/node\_modules/meteor/npm-mongo/node\_modules/mongodb-core/lib/uri\_parser.js:134:26)  
at Array.reduce ()  
at parseQueryStringItemValue (/app/bundle/programs/server/npm/node\_modules/meteor/npm-mongo/node\_modules/mongodb-core/lib/uri\_parser.js:132:30)  
at parseQueryString (/app/bundle/programs/server/npm/node\_modules/meteor/npm-mongo/node\_modules/mongodb-core/lib/uri\_parser.js:407:25)  
at parseConnectionString (/app/bundle/programs/server/npm/node\_modules/meteor/npm-mongo/node\_modules/mongodb-core/lib/uri\_parser.js:523:21)  
at connect (/app/bundle/programs/server/npm/node\_modules/meteor/npm-mongo/node\_modules/mongodb/lib/operations/mongo\_client\_ops.js:195:3)  
at connectOp (/app/bundle/programs/server/npm/node\_modules/meteor/npm-mongo/node\_modules/mongodb/lib/operations/mongo\_client\_ops.js:284:3)  
at executeOperation (/app/bundle/programs/server/npm/node\_modules/meteor/npm-mongo/node\_modules/mongodb/lib/utils.js:416:24)  
at MongoClient.connect (/app/bundle/programs/server/npm/node\_modules/meteor/npm-mongo/node\_modules/mongodb/lib/mongo\_client.js:175:10)  
at Function.MongoClient.connect (/app/bundle/programs/server/npm/node\_modules/meteor/npm-mongo/node\_modules/mongodb/lib/mongo\_client.js:341:22)  
at new MongoConnection (packages/mongo/mongo\_driver.js:177:11)  
at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote\_collection\_driver.js:4:16)  
at Object. (packages/mongo/remote\_collection\_driver.js:38:10)  
at Object.defaultRemoteCollectionDriver (packages/underscore.js:784:19)  
at new Collection (packages/mongo/collection.js:97:40)  
Tried 3 times. Waiting 5 secs…

The databases can see each other:  
rs01:SECONDARY\> rs.status()  
{  
“set” : “rs01”,  
“date” : ISODate(“2020-04-06T12:25:35.496Z”),  
“myState” : 2,  
“term” : NumberLong(3),  
“syncingTo” : “mongo2:27017”,  
“syncSourceHost” : “mongo2:27017”,  
“syncSourceId” : 1,  
“heartbeatIntervalMillis” : NumberLong(2000),  
“optimes” : {  
“lastCommittedOpTime” : {  
“ts” : Timestamp(1586175928, 1),  
“t” : NumberLong(3)  
},  
“readConcernMajorityOpTime” : {  
“ts” : Timestamp(1586175928, 1),  
“t” : NumberLong(3)  
},  
“appliedOpTime” : {  
“ts” : Timestamp(1586175928, 1),  
“t” : NumberLong(3)  
},  
“durableOpTime” : {  
“ts” : Timestamp(1586175928, 1),  
“t” : NumberLong(3)  
}  
},  
“electionParticipantMetrics” : {  
“votedForCandidate” : true,  
“electionTerm” : NumberLong(3),  
“lastVoteDate” : ISODate(“2020-04-06T12:02:17.975Z”),  
“electionCandidateMemberId” : 1,  
“voteReason” : “”,  
“lastAppliedOpTimeAtElection” : {  
“ts” : Timestamp(1586174201, 1),  
“t” : NumberLong(1)  
},  
“maxAppliedOpTimeInSet” : {  
“ts” : Timestamp(1586174201, 1),  
“t” : NumberLong(1)  
},  
“priorityAtElection” : 1,  
“newTermStartDate” : ISODate(“2020-04-06T12:02:17.977Z”),  
“newTermAppliedDate” : ISODate(“2020-04-06T12:02:18.766Z”)  
},  
“members” : [  
{  
“\_id” : 0,  
“name” : “mongo1:27017”,  
“health” : 1,  
“state” : 2,  
“stateStr” : “SECONDARY”,  
“uptime” : 1413,  
“optime” : {  
“ts” : Timestamp(1586175928, 1),  
“t” : NumberLong(3)  
},  
“optimeDate” : ISODate(“2020-04-06T12:25:28Z”),  
“syncingTo” : “mongo2:27017”,  
“syncSourceHost” : “mongo2:27017”,  
“syncSourceId” : 1,  
“infoMessage” : “”,  
“configVersion” : 1,  
“self” : true,  
“lastHeartbeatMessage” : “”  
},  
{  
“\_id” : 1,  
“name” : “mongo2:27017”,  
“health” : 1,  
“state” : 1,  
“stateStr” : “PRIMARY”,  
“uptime” : 1408,  
“optime” : {  
“ts” : Timestamp(1586175928, 1),  
“t” : NumberLong(3)  
},  
“optimeDurable” : {  
“ts” : Timestamp(1586175928, 1),  
“t” : NumberLong(3)  
},  
“optimeDate” : ISODate(“2020-04-06T12:25:28Z”),  
“optimeDurableDate” : ISODate(“2020-04-06T12:25:28Z”),  
“lastHeartbeat” : ISODate(“2020-04-06T12:25:35.363Z”),  
“lastHeartbeatRecv” : ISODate(“2020-04-06T12:25:34.541Z”),  
“pingMs” : NumberLong(0),  
“lastHeartbeatMessage” : “”,  
“syncingTo” : “”,  
“syncSourceHost” : “”,  
“syncSourceId” : -1,  
“infoMessage” : “”,  
“electionTime” : Timestamp(1586174537, 1),  
“electionDate” : ISODate(“2020-04-06T12:02:17Z”),  
“configVersion” : 1  
}  
],  
“ok” : 1,  
“operationTime” : Timestamp(1586175928, 1),  
“$clusterTime” : {  
“clusterTime” : Timestamp(1586175928, 1),  
“signature” : {  
“hash” : BinData(0,“AAAAAAAAAAAAAAAAAAAAAAAAAAA=”),  
“keyId” : NumberLong(0)  
}  
}  
}

Any help or advice would be appreciated.

---

<div class="post-metadata">

**Author:** ![djeantou](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@djeantou](https://forums.rocket.chat/u/djeantou)\
**Post date:** [April 6, 2020, 2:26pm UTC](https://forums.rocket.chat/t/failover-mongodb-server/6404/2 "2020-04-06T14:26:09Z")

</div>

Figured it out. It was the way I structured the envs:  
- MONGO\_URL=mongodb://mongo1:27017,mongo2:27017/rocketchat?replicaSet=rs01&readPreference=primaryPreferred&w=majority  
- MONGO\_OPLOG\_URL=mongodb://mongo1:27017,mongo2:27017/local?replicaSet=rs01
