title: Data not getting saved in the MongoDB from node.js
body: <p>I want to create the rest api using node.js and mongodb
  I am entering all the details and trying it to store it in the mongodb database.</p>
  
  <pre><code>// call the packages we need
  var express    = require('express');
  var bodyParser = require('body-parser');
  var app        = express();
  var morgan     = require('morgan');
  
  // configure app
  app.use(morgan('dev')); // log requests to the console
  
  // configure body parser
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(bodyParser.json());
  
  var port     = process.env.PORT || 8080; // set our port
  
  var mongoose   = require('mongoose');
  // mongoose.connect('mongodb://node:node@novus.modulusmongo.net:27017/Iganiq8o'); // connect to our database
  mongoose.connect('mongodb://localhost:27017');
  var Bear     = require('./app/models/bear');
  // create our router
  var router = express.Router();
  
  // middleware to use for all requests
  router.use(function(req, res, next) {
      // do logging
      console.log('Something is happening.');
      next();
  });
  
  // test route to make sure everything is working (accessed at GET http://localhost:8080/api)
  router.get('/', function(req, res) {
      res.json({ message: 'hooray! welcome to our api!' });   
  });
  
  // on routes that end in /bears
  // ----------------------------------------------------
  router.route('/bears')
  
      // create a bear (accessed at POST http://localhost:8080/bears)
      .post(function(req, res) {
  
          var bear = new Bear();      // create a new instance of the Bear model
          bear.name = req.body.name;  // set the bears name (comes from the request)
          bear.email= req.body.email;  // set the bears email(comes from the request)
  
          bear.save(function(err) {
              if (err)
                  res.send(err);
  
              res.json({ message: 'Bear created!' });
          });
  
  
      })
  
      // get all the bears (accessed at GET http://localhost:8080/api/bears)
      .get(function(req, res) {
          Bear.find(function(err, bears) {
              if (err)
                  res.send(err);
  
              res.json(bears);
          });
      });
  
  // on routes that end in /bears/:bear_id
  // ----------------------------------------------------
  router.route('/bears/:bear_id')
  
      // get the bear with that id
      .get(function(req, res) {
          Bear.findById(req.params.bear_id, function(err, bear) {
              if (err)
                  res.send(err);
              res.json(bear);
          });
      })
  
      // update the bear with this id
      .put(function(req, res) {
          Bear.findById(req.params.bear_id, function(err, bear) {
  
              if (err)
                  res.send(err);
  
              bear.name = req.body.name;
              bear.save(function(err) {
                  if (err)
                      res.send(err);
  
                  res.json({ message: 'Bear updated!' });
              });
  
          });
      })
  
      // delete the bear with this id
      .delete(function(req, res) {
          Bear.remove({
              _id: req.params.bear_id
          }, function(err, bear) {
              if (err)
                  res.send(err);
  
              res.json({ message: 'Successfully deleted' });
          });
      });
  // REGISTER OUR ROUTES -------------------------------
  app.use('/api', router);
  
  // START THE SERVER
  // =============================================================================
  app.listen(port);
  console.log('Magic happens on port ' + port);
  </code></pre>
  
  <p>The Model is given below:- </p>
  
  <pre><code>var mongoose     = require('mongoose');
  var Schema       = mongoose.Schema;
  
  var BearSchema   = new Schema({
      name: String, 
      email: String
  });
  
  module.exports = mongoose.model('Bear', BearSchema);
  </code></pre>
  
  <p>I am trying it to save the name and the email in the mongodb database but only _id is created instead of name, email.</p>
  
  <p>Here is the result:-</p>
  
  <pre><code>[
  {
      "_id": "567f1f92db24304013000001",
      "__v": 0
    },
    {
      "_id": "567f2765db24304013000002",
      "__v": 0
    }
  ]
  </code></pre>
  
  <p>Can anybody tell me why the data are not getting saved in the database.</p>
  
  <p>Please kindly help.</p>
  
  <p>Thanks in Advance.</p>