Javascript client side issues after with Mongodb version > 5.0

Description

Hello,

When we try to upgrade mongodb from version 4.4 we have some javascript client side issues (message not marked as read or as unread, server registration for example) we have to refresh manually the client (browser or electron) to update the display.

The problem appears from Mongodb version 5.x, if we rollback to version 4.4, it returns to normal.

We reproduced the issue on a fresh debian bookworm install with kiss configuration of nginx and mongodb with latest recommended versions.

Could you reproduce and investigate please ?
Thank you in advance.

Server Setup Information

Version of Rocket.Chat Server: 7.4.1
Operating System: Debian GNU/Linux12 (Bookworm)
Deployment Method: tar or docker
Number of Running Instances: 1
DB Replicaset Oplog: wiredTiger (oplog Activated)
NodeJS Version: v22.13.1 - x64
MongoDB Version: > 5.0
Proxy: nginx
Firewalls involved: turned off

±-------------------------------------------+
| SERVER RUNNING |
±-------------------------------------------+
| |
| Rocket.Chat Version: 7.4.1 |
| NodeJS Version: 22.13.1 - x64 |
| MongoDB Version: 7.0.17 |
| MongoDB Engine: wiredTiger |
| Platform: linux |
| Process Port: 3000 |
| Site URL: http://my_ip |
| ReplicaSet OpLog: Enabled |
| Commit Hash: fb0f4eaf59 |
| Commit Branch: HEAD |
| |
±-------------------------------------------+

Steps to reproduce the issue

# apt install g++ build-essential git curl python3 docker docker.io graphicsmagick nginx nginx-full nginx-core rsync
# curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh
# chmod +x nodesource_setup.sh
# bash nodesource_setup.sh
# aptitude install nodejs=22.13.1-1nodesource1
# aptitude hold nodejs
# echo "{\"iptables\": false}" > /etc/docker/daemon.json
# iptables -t nat -A POSTROUTING ! -o docker0 -s 172.17.0.0/16 -j MASQUERADE
# npm install --global yarn
# useradd -M rocketchat && usermod -L rocketchat
# mkdir -p /backups/rocketchat/mongodb /backups/rocketchat/wwwroot/ /backups/rocketchat/mongodb/datas /backups/rocketchat/wwwroot/bundle/
# chown -R rocketchat:rocketchat /backups/rocketchat/wwwroot/
$ curl -fsSL https://deno.land/install.sh | sh
$ curl https://install.meteor.com/?release=2.0 | sh
$ curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz
$ tar -xzf /tmp/rocket.chat.tgz -C /tmp
$ export NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt
$ cd /tmp/bundle/programs/server && npm install --unsafe-perm
$ rsync -avh /tmp/bundle/ /backups/rocketchat/wwwroot/bundle/
# docker pull mongo:7.0
# nano /etc/systemd/system/docker-mongodb.service

[Unit]
Description=MongoDB - docker container
After=docker.service
BindsTo=docker.service

[Service]
StandardOutput=append:/var/log/docker-mongodb/mongodb.log
StandardError=append:/var/log/docker-mongodb/mongodb.log

Environment=NAME=mongodb_container
Environment=IMAGE=mongo:7.0
Environment=PORT=27017
Environment=MONGODB_DIR=/backups/rocketchat/mongodb
Restart=on-failure
RestartSec=10

ExecStartPre=-/usr/bin/docker kill ${NAME}
ExecStartPre=-/usr/bin/docker rm ${NAME}
ExecStart=/usr/bin/docker run -p ${PORT}:${PORT} -v ${MONGODB_DIR}/datas:/data/db -v ${MONGODB_DIR}/dumps:/dump -v ${MONGODB_DIR}/files:/opt/files --name ${NAME} ${IMAGE} --oplogSize 128 --replSet rs01 --storageEngine=wiredTiger
ExecStop=/usr/bin/docker stop ${NAME}

[Install]
WantedBy=multi-user.target

# systemctl daemon-reload
# mkdir /var/log/docker-mongodb/
# service docker-mongodb start
# docker exec -it mongodb_container mongosh --host localhost --port 27017
> rs.initiate({_id: "rs01",members: [{_id: 0,host:"127.0.0.1:27017"}]})
# nano /etc/systemd/system/rocketchat.service

[Unit]
Description=The Rocket.Chat server
After=network.target remote-fs.target nss-lookup.target nginx.service docker-mongod.service

[Service]
User=rocketchat
StandardOutput=append:/var/log/rocketchat/prod.log
StandardError=append:/var/log/rocketchat/prod.log
ExecStart=/usr/bin/node /backups/rocketchat/wwwroot/bundle/main.js

Environment=ROOT_URL=http://my_ip
Environment=PORT=3000
Environment=BIND_IP=my_ip
Environment=INSTANCE_IP=my_ip
Environment=NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt
Environment=MONGO_URL=mongodb://127.0.0.1:27017/rocketchat?replicaSet=rs01&readPreference=primaryPreferred&w=1
Environment=MONGO_OPLOG_URL=mongodb://127.0.0.1:27017/local?replicaSet=rs01
Environment=USE_NATIVE_OPLOG=true

Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

# systemctl daemon-reload
# mkdir /var/log/rocketchat/
# nano /etc/nginx/sites-available/rocketchat

server {
listen 0.0.0.0:80;

rewrite_log off;
access_log /var/log/nginx/rocketchat_access.log;
error_log /var/log/nginx/rocketchat_error.log;
client_max_body_size 5M;

root /dev/null;
location / {
	proxy_pass http://backend.rocket;
	proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection "upgrade";
	proxy_set_header Host $http_host;

	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	proxy_set_header X-Forwarded-Proto https;
	proxy_set_header X-Nginx-Proxy true;
	proxy_redirect off;
}

}

# nano /etc/nginx/sites-available/rocketchat.backend

upstream backend.rocket {
server my_ip:3000;
}

# rm -rf /etc/nginx/sites-enabled/default
# ln -s /etc/nginx/sites-available/rocketchat /etc/nginx/sites-enabled/rocketchat
# ln -s /etc/nginx/sites-available/rocketchat.backend /etc/nginx/sites-enabled/rocketchat.backend
# nginx -t
# service nginx reload
# service rocketchat start
# tail -f /var/log/rocketchat/prod.log

While running the javascript debugger on client side, i got this exception when i mark a message as read:
Cannot find module ‘/node_modules/buffer/index.js’

I don’t have this problem with mongo 4.4, since mongo 5, the client try to import a nodejs module buffer but it looks like it’s not added during the installation process

Hello, the problem seems to disappear if i remove the USE_NATIVE_OPLOG=true from environment variable defined in service section of rocketchat systemd config file

if someone could confirm this option is not compatible with version of mongodb > 5.0 should be great, thank you

Simplify.