Git Product home page Git Product logo

prime_peer_db_02's Introduction

prime_peer_db_01

In this exercise you'll be creating a MongoDB application to store customer information. The purpose of this exercise is to help understand the way Document Databases function, and how to interact with them.

###Make sure MongoDB installed, and run mongod. Run the command mongod from the terminal. If it fails, follow the installation guide.

###Install Robomongo Get it here.

Use it. Love it.

###Create a new NodeJS application. Create a basic NodeJS application with an express server. Add an index file as well. Make sure you add an app.get to send your index file!

app.get('/', function(request, response, next){
    request.sendFile(path.resolve(__dirname, '../views/index.html'));
});

###Get connected to your database. Put the following into your server side js file (I typically call mine server.js, and a lot of people use app.js)

// Mongo setup
var mongoose = require('mongoose');

var mongoURI = "mongodb://localhost:27017/assignments";
var MongoDB = mongoose.connect(mongoURI).connection;
MongoDB.on('error', function (err) {
  if (err) {
    console.log('mongodb connection error', err);
  } else {
    console.log('mongodb connection successful');
  }
});

MongoDB.once('open', function () {
  console.log('mongodb connection open');
});

What does it do? The first line requires MongoDB and gives us access to the client. The second function connects to the database and a document store named assignments.

NOTE

How to install a module npm install mongoose --save

How to remove a module npm remove mongodb --save

###Create a "Assignment" Model In your Node application, create a folder called models. Within that folder create a model named assignments and give it some properties that an assignment would have. The minimum requirements are a student name, score, date_completed. The more, the better!

MongoDB Types

###Create a CRUD operations for the model.

Use a combination of REST methods and Mongo methods to make a Create, Update, Read and Delete method.

Use postman to test each method.

###Tying it all together

In your index file, display a list of all assignments when the page loads.

Once you have that working add a button next to each assignment record. When the button is clicked will delete the record from the database using Ajax.

##HARD MODE

Add another file called create.html. Add a form for creating new records using a form postback. Make sure you specify method="post" in the form tag.

##PRO MODE

Finally, add another button to each record on the index that allows the user to update the database entry. This can either be done via ajax or in a form on a new page.

Final, allow users to update

prime_peer_db_02's People

Contributors

tracyfuller avatar

Watchers

 avatar  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.