var express = require('express');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var router = express.Router();

var Song = new Schema({
  name: String
});
var Songs = mongoose.model('Song', Song);

// List
router.get('/', function(req, res) {
  Songs.find({}, function(err, song) {
    if(err) {
      console.log('Error');
    }
    res.send('LIST');
  });
});

// Create
router.post('/', function(req, res) {
  req.db.collection(tableName).find().toArray(function(err, results) {
    if(err) {
      console.log('Error');
    }
    res.send('CREATE');
  });
});

// Read
router.get('/:id', function(req, res) {
  req.db.collection(tableName).find().toArray(function(err, results) { 
    if(err) {
      console.log('Error');
    }
    res.send('READ');
  });
});

// Update
router.put('/:id', function(req, res) {
  req.db.collection(tableName).save(req.body, function(req, res) {
    if(err) {
      console.log('Error');
    }
    res.send('UPDATE');
  });
});

// DELETE
router.delete('/:id', function(req, res) {
  req.db.collection(tableName).delete(req.body, function(req, res) {
    if(err) {
      console.log('Error');
    }
    res.send('DELETE');
  });
});

module.exports = router;

@@ -430,52 +430,29 @@
 %7B%0A  
-req.db.collection(tableName).find().toArray(
+Songs.save(req.body, 
 func
@@ -540,17 +540,30 @@
 ('CREATE
-'
+: ' + req.body
 );%0A  %7D);
@@ -622,52 +622,34 @@
 %7B%0A  
-req.db.collection(tableName).find().toArray(
+Songs.find(req.params.id, 
 func
@@ -736,17 +736,35 @@
 nd('READ
-'
+: ' + req.params.id
 );%0A  %7D);
@@ -825,36 +825,13 @@
 %7B%0A  
-req.db.collection(tableName)
+Songs
 .sav
@@ -847,32 +847,36 @@
 y, function(
-req
+err
 , res
+ults
 ) %7B%0A    if(e
@@ -935,17 +935,35 @@
 ('UPDATE
-'
+: ' + req.params.id
 );%0A  %7D);
@@ -1027,36 +1027,13 @@
 %7B%0A  
-req.db.collection(tableName)
+Songs
 .del
@@ -1036,28 +1036,33 @@
 .delete(req.
-body
+params.id
 , function(r
@@ -1140,17 +1140,35 @@
 ('DELETE
-'
+: ' + req.params.id
 );%0A  %7D);

Update songs.js