Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
package-lock.json
credentials.js
.env*
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Our MongoDB Api

This project showcases what we've learned to make an api that will access a "movie" collection in our mongoDB database

## To get started

1) Clone it locally and run ```npm i``` (in the terminal) to install all dependencies
2) rename the ```credentials-example.js``` to ```credentials.js``` and edit the ```uri``` string to either be the one you get from your own cloud.mongodb.com cluster (under the "connect" button) OR you can us ```mongodb://localhost:27017``` if you want to connect to a local instance.
3) you can add new movies by sending a valid JSON body to```http://localhost:4001/add-movie``` and get movies by going to ```http://localhost:4001/get-movies```
1 change: 1 addition & 0 deletions credentials-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const uri = ' replace this string (from quote to quote) with the full string from cloud.mongodb.com or mongodb://localhost:27017 like we had before '
9 changes: 8 additions & 1 deletion mongoConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import { MongoClient } from 'mongodb'
import dotenv from 'dotenv'
dotenv.config()

// If you'll be using the credentials then rename the credentials-example.js to credendials.js and add your info
// import { uri } from "./credentials.js"

// If you're connecgting to your local server on your laptop
// const uri = 'mongodb://localhost:27017'

// If you're using the .env file with a MONGO_URI entry
const uri = process.env.MONGO_URI
// uri = 'mongodb://localhost:27017'


const client = new MongoClient(uri) // creating client mongo instance
const db = client.db('bocacode-test') // connecting to db = bocacod-test
Expand Down
9 changes: 8 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Node API with MongoDb
This project showcases what we've learned to make an api that will access a "movie" collection in our mongoDB database

## To get started

1. After cloning project install dependencies with `npm i`
2. Connect to MongoDB (if local start with `brew services start mongo-community)
3. Run API with nodemon
3. Run API with nodemon

## How to use it:
you can add new movies by sending a valid JSON body to```http://localhost:4001/add-movie``` and get movies by going to ```http://localhost:4001/get-movies```