# Replication settings for MongoDB used in Rocket.Chat

**URL:** <https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544>\
**Category:** Community Support\
**Created:** [September 11, 2024, 7:19am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544 "2024-09-11T07:19:26Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Furret](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/furret/32/5529_2.png) [@Furret](https://forums.rocket.chat/u/Furret)\
**Post date:** [September 11, 2024, 7:19am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/1 "2024-09-11T07:19:26Z")

</div>

### Description

I have been ordered by the boss of Team Rocket to implement redundancy for MongoDB used in Rocket.Chat.

I set up MongoDB with a Primary, Secondary, and Arbiter configuration, but when the Primary goes down, my message inputs get grayed out, and the messages I send are not visible to other users.I have confirmed that setting up two Secondaries along with the Primary solves the issue.I believe this is due to the behavior of MongoDB’s ChangeStream API.

If you have any knowledge on how to configure MongoDB so that Rocket.Chat works with a Primary, Secondary, and Arbiter setup, I would greatly appreciate your advice.

### Server Setup Information

- Version of Rocket.Chat Server: 6.5.2
- Operating System: Red Hat Enterprise Linux 8.8
- Deployment Method: tar
- Number of Running Instances: 2
- DB Replicaset Oplog: true
- NodeJS Version: 14.21.3
- MongoDB Version: 5.0.21
- Proxy: nginx
- Firewalls involved:

### Any additional Information

This is the configuration information for the replica set.

```auto
{
        "_id" : "chat",
        "version" : 9,
        "term" : 61,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "192.168.21.203:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 2,
                        "tags" : {

                        },
                        "secondaryDelaySecs" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 1,
                        "host" : "192.168.21.204:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "secondaryDelaySecs" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 2,
                        "host" : "192.168.21.248:27017",
                        "arbiterOnly" : true,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 0,
                        "tags" : {

                        },
                        "secondaryDelaySecs" : NumberLong(0),
                        "votes" : 1
                }
        ],
        "protocolVersion" : NumberLong(1),
        "writeConcernMajorityJournalDefault" : true,
        "settings" : {
                "chainingAllowed" : true,
                "heartbeatIntervalMillis" : 2000,
                "heartbeatTimeoutSecs" : 10,
                "electionTimeoutMillis" : 10000,
                "catchUpTimeoutMillis" : -1,
                "catchUpTakeoverDelayMillis" : 30000,
                "getLastErrorModes" : {

                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                },
                "replicaSetId" : ObjectId("667d056118c880954dc247a5")
        }
}

```

---

<div class="post-metadata">

**Author:** ![reetp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/reetp/32/5546_2.png) [@reetp](https://forums.rocket.chat/u/reetp)\
**Post date:** [September 11, 2024, 9:32am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/2 "2024-09-11T09:32:30Z")

</div>

> [@Furret](#):
>
> Version of Rocket.Chat Server: 6.5.2

Upgrade. First you are only on 6.5.2 and the latest of that series was 6.5.8 - you really need to keep up to date with updates - there were security fixes you have missed which put you at risk of getting hacked 😨

On top of that:

[https://docs.rocket.chat/docs/support-prerequisites](https://docs.rocket.chat/docs/support-prerequisites)

> Each release of Rocket.Chat comes with a six-month support period from its release date.

> Once this period expires, hosted services such as the Push Gateway and Marketplace will cease to function for that particular version.

[https://docs.rocket.chat/docs/version-durability](https://docs.rocket.chat/docs/version-durability)

Your version was EOL in June 2024. You need to be on a higher version - I’d suggest 6.11.2

Can’t help you otherwise.

---

<div class="post-metadata">

**Author:** ![Furret](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/furret/32/5529_2.png) [@Furret](https://forums.rocket.chat/u/Furret)\
**Post date:** [September 12, 2024, 12:14am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/3 "2024-09-12T00:14:06Z")

</div>

Thank you for your response. I understand about the support period.  
As expected, upgrading is necessary for security reasons.  
I will report to our boss, Giovanni. I will check the operation again after the upgrade.

---

<div class="post-metadata">

**Author:** ![Furret](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/furret/32/5529_2.png) [@Furret](https://forums.rocket.chat/u/Furret)\
**Post date:** [September 12, 2024, 4:59am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/4 "2024-09-12T04:59:25Z")

</div>

I tried setting up the latest version in a new environment and checked it.  
The same graying out issue occurs in this environment as well.  
Should I be scrutinizing the source code or studying MongoDB…?

- Version of Rocket.Chat Server: 6.12.0
- Operating System: Rocky Linux 9.2
- Deployment Method: tar
- Number of Running Instances: 1
- DB Replicaset Oplog: true
- NodeJS Version: 14.21.3
- MongoDB Version: 6.0.14
- Proxy: nginx
- Firewalls involved:

---

<div class="post-metadata">

**Author:** ![reetp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/reetp/32/5546_2.png) [@reetp](https://forums.rocket.chat/u/reetp)\
**Post date:** [September 12, 2024, 4:25pm UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/5 "2024-09-12T16:25:18Z")

</div>

I have no idea about arbiter and whether it would or should work.

You have a replica set?

As normal debug procedure I’d suggest you look at logs first.

So Rocket.Chat logs ands the Mongo logs.

See where that leads.

---

<div class="post-metadata">

**Author:** ![Furret](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/furret/32/5529_2.png) [@Furret](https://forums.rocket.chat/u/Furret)\
**Post date:** [September 13, 2024, 5:35am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/6 "2024-09-13T05:35:49Z")

</div>

Thank you for your response.  
By using an arbiter, we can set up replication with a low-spec server.  
Team Rocket doesn’t have much money, so we are focused on saving costs.

> **[Replica Set Arbiter - MongoDB Manual v6.0](https://www.mongodb.com/docs/v6.0/core/replica-set-arbiter/)**

For now, I will patiently check the logs.  
I’ll consult you again if there is any progress.  
Thank you.

---

<div class="post-metadata">

**Author:** ![reetp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/reetp/32/5546_2.png) [@reetp](https://forums.rocket.chat/u/reetp)\
**Post date:** [September 13, 2024, 7:56am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/7 "2024-09-13T07:56:21Z")

</div>

> [@Furret](#):
>
> By using an arbiter, we can set up replication with a low-spec server.

I suspect that is an unsupported option. Sorry.

How many users are you expecting to support?

---

<div class="post-metadata">

**Author:** ![Furret](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/furret/32/5529_2.png) [@Furret](https://forums.rocket.chat/u/Furret)\
**Post date:** [September 13, 2024, 8:10am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/8 "2024-09-13T08:10:41Z")

</div>

I can’t say it too loudly, but Team Rocket is an organization made up of 50 to 100 people.

---

<div class="post-metadata">

**Author:** ![reetp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/reetp/32/5546_2.png) [@reetp](https://forums.rocket.chat/u/reetp)\
**Post date:** [September 13, 2024, 8:34am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/9 "2024-09-13T08:34:55Z")

</div>

Kk.

In which case you don’t need anything fancy.

I run similar on a VM with 2x cpu, 6gb Ram, docker rocket & single mongo.

Think Rocket is limited to 4Gb.

It’s not massively busy but it just idles.

There is no such thing as “free”, even with open source. You need to budget a little somewhere.

You can get a VM with 4gb at say vultr or digital ocean for around $20 per month. Between 50 of you? Couple of dollars each per year.

---

<div class="post-metadata">

**Author:** ![Furret](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/furret/32/5529_2.png) [@Furret](https://forums.rocket.chat/u/Furret)\
**Post date:** [September 13, 2024, 9:04am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/10 "2024-09-13T09:04:19Z")

</div>

Thank you for your response.

The purpose of setting up replication was not for load balancing but for redundancy.  
The goal is to ensure that if one MongoDB server fails, another MongoDB server can take over, allowing Rocket.Chat services to continue.  
It seems that MongoDB has a separate mechanism for load balancing.

> **[Sharding - MongoDB Manual v6.0](https://www.mongodb.com/docs/v6.0/sharding/)**
>
> Scale MongoDB deployments horizontally. Use sharding to distribute data across multiple machines, supporting large datasets and high throughput operations.

Indeed, it is difficult to achieve everything without spending money.  
For now, having one primary server and two secondary servers seems sufficient, so I will proceed with that.  
I hope the information about the issues with having a primary, secondary, and arbiter setup is helpful.

Thank you.

---

<div class="post-metadata">

**Author:** ![reetp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/reetp/32/5546_2.png) [@reetp](https://forums.rocket.chat/u/reetp)\
**Post date:** [September 13, 2024, 10:44am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/11 "2024-09-13T10:44:21Z")

</div>

> [@Furret](#):
>
> The purpose of setting up replication was not for load balancing but for redundancy.

I think if you are operating on a limited budget then this is a) overkill and b) not cheap. Hey ho.

> we are focused on saving costs

Redundancy costs more…

I can honestly say that in the several years that I have run my servers the only downtime has been when I have updated. That’s it. It has been reliable and robust.

I’d spend my money on decent reliable hardware and have some good backups - I think you are chasing some ghosts here.

> [@Furret](#):
>
> I hope the information about the issues with having a primary, secondary, and arbiter setup is helpful.

Not really I’m afraid - you have not got a cure and I don’t believe arbiter/sharding is supported.

Ah yes - note this has been covered many times before. You need to search thoroughly.

> [@Rocketchat Support for sharded cluster in MongoDB](https://forums.rocket.chat/t/rocketchat-support-for-sharded-cluster-in-mongodb/20303/2):
>
> I don’t believe there is any change to this. Upgrade for the security fix.

So sharding isn’t, and won’t ever be, supported.

If you need redundancy that badly then invest the money and run a couple of Mongo servers which is supported.

---

<div class="post-metadata">

**Author:** ![Furret](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/furret/32/5529_2.png) [@Furret](https://forums.rocket.chat/u/Furret)\
**Post date:** [September 17, 2024, 12:15am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/12 "2024-09-17T00:15:04Z")

</div>

Thank you for your response. I learned a lot from it. Thank you very much 😀

---

<div class="post-metadata">

**Author:** ![reetp](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/reetp/32/5546_2.png) [@reetp](https://forums.rocket.chat/u/reetp)\
**Post date:** [September 17, 2024, 8:23am UTC](https://forums.rocket.chat/t/replication-settings-for-mongodb-used-in-rocket-chat/20544/13 "2024-09-17T08:23:51Z")

</div>

Theory v practice 🙂

For 50-100 one instance will be fine. Run a separate test box for testing upgrades, and do upgrades slowly and incrementally with a good eye on github issues.

A few notes for you!

> <https://gist.github.com/reetp/ddd0580ab9f9397715da1c14cd85a73c#rocketchat-administration>

You only need to think about increasing backend resources above 200 users due to constraints with node etc.
