MongoDB cheat sheet

17 May,2017 by Tom Collins

MongoDB is an open-source NoSQL  document-oriented database program. I’ve recently started supporting MongoDB . This is my quick notes to  support MongoDB


How to install MongoDB Enterprise on Red Hat Linux

--create a repo file and insert the text below

vi /etc/yum.repos.d/mongodb-enterprise.repo


name=MongoDB Enterprise Repository





--install the package

sudo yum install -y mongodb-enterprise


Create the user Administrator 

Note:Once you've created the admin Users, you'll need to disconnect from the Mongo Shell & restart the Mongo Server

use admin
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]



Start the MongoDB service

sudo service mongod start


Start at the next system reboot

sudo chkconfig mongod on


To allow remote connections

Step1 : how to create a user in a db


    user: 'robert',

    pwd: 'myM0ng0_pw',

    roles: [{ role: 'readWrite', db:'testdb'}]


Step 2 : Get the private address

/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'


Step 3:edit mongo configuration file

--get private address from step 2 and add to bindip

vim /etc/mongod.conf

--change #security to:


   authorization: enabled


Step 4: Then from the terminal you can run:

First you must have the mongo cli installed in your system (

mongo -u username -p password

List all databases on a Mongo Server

show dbs

Show current Mongo db



Author: Rambler(


Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment on MongoDB cheat sheet

Comments are moderated, and will not appear until the author has approved them. | DB2 Performance Tuning | DBA DB2:Everything | FAQ | Contact | Copyright