Giter VIP home page Giter VIP logo

mongo-i-mini's Introduction

Mongo Mini

Topics:

  • Databases
  • MongoDB
  • ORMs
  • Mongoose
  • Create/Read/Update/Delete operations

Description

You'll write a server that lets you create and read Bears through MongoDB. Much of the knowledge from Node and Express will carry over to this mini project, where you'll interface with a database in your route handlers.

Running the Project

  • Install MongoDB.
  • cd into your project directory.
  • Run npm install to download the dependencies.
  • Run mongod --dbpath data and keep it running in a separate terminal.
  • Write your implementation, as per the instructions below.
  • To test your application at any point, run npm start to start the server. Then, you can make requests to http://localhost:3000 in Postman or in your browser! To make POST requests, you'll need to use Postman. Craft the correct requests to test your implementation!

Instructions

Schema

Create a schema for the Bears collection. A schema is a description of the format of documents within a collection. In this case, each Bear is a document of the form:

{
  species: "American Black Bear",
  latinName: "Ursus americanus",
  createdAt: Mon Aug 14 2017 12:50:16 GMT-0700 (PDT)
}

In models.js, write the schema for the Bears collection. Make the field createdAt default to the current date.

POST /bears

When the client makes a POST request to /bears:

  • Ensure the client passes species and latinName parameters in the request body. If there's an error, respond with an appropriate status code, and send a JSON response of the form { error: "Some useful error message" }.

  • Create and save a new Bear document. If there's an error while saving, send that error as a JSON response, and set the status code to STATUS_SERVER_ERROR (Internal Server Error).

  • Otherwise, if everything is successful, send the Bear document as a JSON response.

GET /bears

When the client makes a GET request to /bears, read all the Bear documents from MongoDB as an array. Send that array as a JSON response to the client.

If there's an error in retrieving the documents, send that error to the client in a JSON response. Set the status code to STATUS_SERVER_ERROR (Internal Server Error), as the server couldn't fetch the documents for some reason.

GET /bears/:id

When the client makes a GET request to /bears/:id (remember, :id is a parameter embedded in the URL, not in the query-string):

  • Find the Bear document associated with the given id. If there's an error, send that error as a JSON response, and set the status code to STATUS_SERVER_ERROR (Internal Server Error).

  • Otherwise, if everything is successful, send the Bear document as a JSON response.

mongo-i-mini's People

Contributors

karthikv avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.