be-course-18-19

MongoDB Server

An express-server but with a mongodb database.

Install

First, get the example:

git clone git@github.com:cmda-be/course-17-18.git
cd course-17-18/examples/mongodb-server
npm install

Create a database in another terminal tab:

mkdir db
mongod --dbpath db

Back in the original tab, open the mongo REPL:

mongo

…and run the following code to populate the database:

> use mymoviewebsite
switched to db mymoviewebsite
> db.movies.insert({
   title: 'Evil Dead',
   plot: 'Five friends travel to a …',
   description: 'Five friends head to a …'
 })
WriteResult({ "nInserted" : 1 })
> db.movies.insert({
   title: 'The Shawshank Redemption',
   plot: 'Two imprisoned men bond over …',
   description: 'Andy Dufresne is a …'
 })
WriteResult({ "nInserted" : 1 })

Press CTRL+C to exit.

Now, add a .env file with the following info (replacing the values with actual values):

DB_HOST=localhost
DB_PORT=myport
DB_NAME=mydatabase

Finally, start the server with:

npm start

Changes

The following commits show how this example was created:

License

MIT © Titus Wormer