I have created a droplet via DigitalOcean with Ubuntu 16.04. I want to deploy my website on the server and I need my nodejs app and mongodb on the server.
I had no problem setting up the nodejs app. I am using pm2 with nginx as reverse proxy and letsencrypt for https.
So, to the problem. I have no idea how to connect to my mongodb server. I have installed mongodb. When I run sudo systemctl status mongodb
this comes in the output:
mongodb.service - High-performance, schema-free document-oriented database
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2017-06-28 13:12:41 UTC; 2h 4min ago
Main PID: 13918 (mongod)
Tasks: 20
Memory: 61.9M
CPU: 1min 21.003s
CGroup: /system.slice/mongodb.service
└─13918 /usr/bin/mongod --quiet --config /etc/mongod.conf
Log file looks like this after start of mongod:
2017-06-28T13:12:41.583+0000 I CONTROL [initandlisten] MongoDB starting : pid=13918 port=27017 dbpath=/var/lib/mo$
2017-06-28T13:12:41.583+0000 I CONTROL [initandlisten] db version v3.2.14
2017-06-28T13:12:41.583+0000 I CONTROL [initandlisten] git version: 92f6668a768ebf294bd4f494c50f48459198e6a3
2017-06-28T13:12:41.583+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2017-06-28T13:12:41.583+0000 I CONTROL [initandlisten] allocator: tcmalloc
2017-06-28T13:12:41.583+0000 I CONTROL [initandlisten] modules: none
2017-06-28T13:12:41.583+0000 I CONTROL [initandlisten] build environment:
2017-06-28T13:12:41.583+0000 I CONTROL [initandlisten] distmod: ubuntu1604
2017-06-28T13:12:41.583+0000 I CONTROL [initandlisten] distarch: x86_64
2017-06-28T13:12:41.583+0000 I CONTROL [initandlisten] target_arch: x86_64
2017-06-28T13:12:41.583+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127$
2017-06-28T13:12:41.643+0000 I - [initandlisten] Detected data files in /var/lib/mongodb created by the 'wi$
2017-06-28T13:12:41.643+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=2$
2017-06-28T13:12:42.482+0000 I CONTROL [initandlisten]
2017-06-28T13:12:42.483+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is$
2017-06-28T13:12:42.483+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-06-28T13:12:42.483+0000 I CONTROL [initandlisten]
2017-06-28T13:12:42.483+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is $
2017-06-28T13:12:42.483+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2017-06-28T13:12:42.483+0000 I CONTROL [initandlisten]
2017-06-28T13:12:42.491+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with direct$
2017-06-28T13:12:42.491+0000 I NETWORK [initandlisten] waiting for connections on port 27017
2017-06-28T13:12:42.491+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
My config files looks like this:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bind
Ip: 127.0.0.1
#processManagement:
#security:
#operationProfiling:
#repli
cation:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
I have for example tried this without luck:
mongoose.connect('mongodb://127.0.0.1:27017/DB');
The big question is how I should connect to the mongodb database that we can see are running as it should, as we can see in the logs. Do I have to configure nginx to get this to work or do I have the wrong url?
Thanks for the help!