06.mongo
Install MongoDB v8
[!IMPORTANT]
If you use VM, set CPU type to "HOST" for this VM. (Recommended CPU is at least Intel(R) Xeon(R) CPU E2690v4)
- Import MongoDB repo key
sudo apt install gnupg curl
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \
--dearmor
- Add MongoDB repository into your Ubuntu system.
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
- Install
sudo apt update && sudo apt -y install mongodb-org
- Run
systemctl enable mongod --now
Update MongoDB
If you have an older version, please perform the update sequentially 6.0 > 7.0 > 8.0
Example update v7 to v8
- Connect to db
mongosh
- Check current version
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 });
- Set version
db.adminCommand({ setFeatureCompatibilityVersion: "8.0" });
- Check updated FCV
db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 });
MongoDB Disk Space Reclamation (GridFS)
- The Issue When files are deleted from GridFS (fs.chunks), MongoDB keeps the disk space pre-allocated for future use. This creates "holes" (fragmentation) in the data files, and the OS does not see the freed space.
root@rbt:/var/lib/mongodb# ls -lah
total 73G
drwxr-xr-x 4 mongodb mongodb 4,0K апр 15 22:15 .
drwxr-xr-x 52 root root 4,0K дек 3 11:38 ..
-rw------- 1 mongodb mongodb 32K апр 15 00:59 collection-0--6991510166517528651.wt
-rw------- 1 mongodb mongodb 73G апр 15 22:15 collection-10--6991510166517528651.wt
- Check Reclaimable Space
db.fs.chunks.stats().wiredTiger["block-manager"]["file bytes available for reuse"] / 1024 / 1024 / 1024
result:
rbt> db.fs.chunks.stats().wiredTiger["block-manager"]["file bytes available for reuse"] / 1024 / 1024 / 1024
|
51.21324157714844
- Run Reclamation (Compact)
// 'force: true' is required if running on a Primary node
db.runCommand({ compact: 'fs.chunks', force: true })