0

I am following a 'Web Dev Simplified' tutorial using AWS-Cloud9 Ubuntu environment. Everything was going well until I had to connect to the mongodb. The db seemed to install fine with...

sudo apt install -y mongodb

and is running.

ubuntu:~/environment $ sudo systemctl status mongodb
● mongodb.service - An object/document-oriented database
   Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-06-11 13:19:28 UTC; 20min ago
     Docs: man:mongod(1)
 Main PID: 17781 (mongod)
    Tasks: 23 (limit: 1152)
   CGroup: /system.slice/mongodb.service
           └─17781 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf

Jun 11 13:19:28 ip-172-31-16-249 systemd[1]: Started An object/document-oriented database.

The tutorial uses mongoose and throws an error on connect. Here is the connection string

mongoose.connect("mongodb://127.0.0.1:27017/examrooms",{useNewUrlParser: true})
const db=mongoose.connect()

Here is the error

MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.

Examining the mongodb.conf file shows the following

sudo cat /etc/mongodb.conf
# mongodb.conf

# Where to store the data.
dbpath=/var/lib/mongodb

#where to log
logpath=/var/log/mongodb/mongodb.log

logappend=true

bind_ip = 127.0.0.1
#port = 27017

Security is off by default. So I have the ip correct and am assuming the port is default to 27017.

Clearly am passing a string as the uri, so is this as symptom of something else? Perhaps permissions? Am stumped. Any pointers are really appreciated.

DaveMac
  • 76
  • 10

2 Answers2

0

please take a look in this link : https://community.c9.io/t/setting-up-mongodb/1717

sudo apt-get install -y mongodb-org $ mkdir data $ echo 'mongod --bind_ip=$IP --dbpath=data --nojournal --rest "$@"' > mongod $ chmod a+x mongod

  • Thanks for a super fast response. I tried the above (without a new install) and received the following error when executing ./mongod Error parsing command line: unrecognised option '--rest' Is there a difference between mongodb and mongodb-org? – DaveMac Jun 11 '19 at 14:04
  • I removed the —rest and it seemed to work. It left me in some kind of shell and I was unable to start my web server to test. – DaveMac Jun 12 '19 at 17:04
0

Ive resolved this now. It seemed that the default dbpath was /var/lib/mongodb

I needed to create a data directory in my project and set the dbpath to that in /etc/mongodb.conf

I also needed to ensure the correct permission were set up for Mongodb to access this new folder. As am using AWS Cloud9 I used

sudo chown mongodb:mongodb /home/ubuntu/environemnt/data/

A few tweaks to the tutorial (as some of it was outdated) and all is good.

DaveMac
  • 76
  • 10