I've found it's particularly import to not jump MongoDB versions when upgrading.
Use the upgrade notes on each version's Release Notes
The basics of upgrading are this:
Verify the running version
mongod --version
Check the Feature Compatibility Version. The version shown here should be the same as what is currently installed.
mongo
use admin
db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
Stop MongoDB
systemctl stop mongod.service
systemctl status mongod.service
Change the version number on the APT repo (consult the MongoDB website for how to correctly setup their repo)
#deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main
deb http://repo.mongodb.org/apt/debian bullseye/mongodb-org/6.0 main
Install the new version
apt update
apt upgrade
Enter into the MongoDB Shell
mongosh
Select the admin database
use admin
Set the Feature Compatibility Version for the new version
db.adminCommand( { setFeatureCompatibilityVersion: "6.0" } )
Restart MongoDB to ensure all changes are applied
systemctl stop mongod.service
systemctl status mongod.service