/ MongoDB

Useful stuff on Mongo DB on Ubuntu 16.04

Ran into few very irritating issues related to MongoDB. Here are some notes for future reference:

  • Path for mongodb systemctl service: /lib/systemd/system/mongod.service .. open it up .. its self explanatory
  • Path on mongodb conf file: /etc/mongod.conf ... configure using that instance!
  • Enable service using: sudo systemctl enable mongod (NOTE ... NOT mongodb ... no b at the end! WTF!
  • Restart service using: sudo systemctl restart mongod
  • Want to switch between user logins ... use sudo -u user2 bash ... verify using whoami

Watch the mongodb log using: sudo tail -F /var/log/mongodb/mongod.log

Upgrading mongodb:

Upgrade to 3.4

wget "https://repo.mongodb.org/apt/ubuntu/dists/xenial/mongodb-org/3.4/multiverse/binary-amd64/mongodb-org-server_3.4.18_amd64.deb"

  • dpkg -x package.deb /tmp/out

  • Change to mongodb

su root ... sudo -u mongodb bash

Upgrade to 3.6

Download 3.6 binary from https://www.mongodb.com/download-center/community

wget "https://repo.mongodb.org/apt/ubuntu/dists/xenial/mongodb-org/3.6/multiverse/binary-amd64/mongodb-org-server_3.6.9_amd64.deb"

Exract deb file

dpkg -x mongodb-org-server_3.6.9_amd64.deb ~/temp/mongodb-org-server_3.6.9_amd64

Change directory cd ~/temp/mongodb-org-server_3.6.9_amd64

Change to mongodb sudo -u mongodb bash

Run 3.6 version of server:
./usr/bin/mongod --version
./usr/bin/mongod --config /etc/mongod.conf

Check compatibility parameter: db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )

Set feature compatibility to 3.6

db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )

Now finally ... start the server with the 4.0 version!

Set compatibility to 4.0!
db.adminCommand( { setFeatureCompatibilityVersion: "4.0" } )

Now ... need to migrate to WiredTiger! .... To Be continued ... Release Notes for MongoDB 4.0 — MongoDB Manual

List databases .... after authentication!

db.adminCommand( { listDatabases: 1 } )

Get list of collections

Mongodump with authentication!

mongodump --uri mongodb://username:pwd@host-ip:27017/xeonss -o ~/temp/mongodb_xeonss