MongoDB install and setup guide for 2018

Haven’t found good guide to kickstart a self hosted mongodb instance. Alternatively for mongodb as a service I recommend using Mongodb Atlas: (500MB free database storage)


Follow this guide:


Nice config:

Configure for remote access

Allow remote access:

Close ports

sudo apt-get install  mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools

sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow proto tcp from any to any port 80,443

sudo ufw deny from any to any port 27017
sudo ufw allow from YOUR_IP_COMES_HERE/32 to any port 27017
sudo ufw status

Error while using pymongo 3.6 with mongodb 3.6 pymongo.errors.ServerSelectionTimeoutError: No replica set members found yet

Error while connecting remotely

mongo  --host -u myuser -p mypass --authenticationDatabase 'test'
MongoDB shell version v3.6.3
connecting to: mongodb://
2018-03-26T21:37:16.205+0100 E QUERY    [thread1] Error: network error while attempting to run command 'isMaster' on host ''  :
[email protected]/mongo/shell/mongo.js:251:13
exception: connect failed

Create new user

use admin
    user: "AdminSammy",
    pwd: "AdminSammy'sSecurePassword",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]

Disable SSL

  port: 27017
    #  allowConnectionsWithoutCertificates: true
    mode: disabled
sudo systemctl restart mongod
mongo --host -u testuser -p testpass --authenticationDatabase 'test'