An express-server but with a mongodb database.
First, get the example:
git clone [email protected]: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
The following commits show how this example was created:
02d1df2
add example9dfed77
add mongodb, dotenv as dependenciesf69654a
add gitignorecc7eb63
replaceid
with_id
dd672e3
add mongo connection4cb4221
use mongo for list of movies1f20d06
use mongo for detail of moviee429b67
use mongo to add a movie2c7cc94
use mongo to remove a moviee569692
remove superfluous data17afc59
remove superfluous dependencies