title: Mongoose .save() not saving to database?
body: <p>I am having problem with Mongoose .save method. The database never gets created and data do not get saved, and does not throw any errors. I've exhausted google and stackoverflow looking at similar suggestions with no luck, so throwing it open to anyone who can help me!</p>
  
  <p><strong>My POST request is made with:</strong></p>
  
  <pre><code>export function registerUser({ email }) {
    return function(dispatch) {
      axios.post(`${API_URL}/auth/register`, { email })
      .then(response =&gt; {
        dispatch({ type: AUTH_USER });
      })
      .catch((error) =&gt; {
        errorHandler(dispatch, error.response, AUTH_ERROR)
      });
    }
  }
  </code></pre>
  
  <p>I made several POST requests and all get successful status back from API with sever config: <code>{'database': 'mongodb://localhost/practicedb', 'port': process.env.PORT || 3000}</code>, yet the data never gets saved and database (practicedb) doesn't show up on Terminal. </p>
  
  <p><strong>With a Mongoose Schema (user.js):</strong></p>
  
  <pre><code>var UserSchema = new Schema({
    email: {
      type: String,
      lowercase: true,
      unique: true,
      required: true
    },
  })
  </code></pre>
  
  <p><strong>API controller</strong> </p>
  
  <p>That receives the email string POST request, and then if nothing is entered in the text field, it sends back a 422 error, and inside <code>User.findOne</code>, if the email already exists in the database, then it throws a 422 error and if not, does <code>user.save</code> to save it in the database. But .save does not work with no errors and the database doesn't even get created. </p>
  
  <pre><code>"use strict";
  
  const User = require('../models/user')
  
  exports.register = function(req, res, next) {
    const email = req.body.email;
  
    if(!email) {
      return res.status(422).send({ error: 'You must enter an email address.'})
    }
  
    User.findOne({ email: email }, function(err, existingUser) {
      if(err) { return next(err); }
  
      if(existingUser) {
        return res.status(422).send({ error: 'That email address is already in use.'})
      }
      let user = new User({
        email: email,
      })
      user.save(function(err, user) {
        if(err) { return next(err); }
        res.status(201).json({
          user: user,
        })
      })
    })
  }
  </code></pre>
  
  <p><strong>EDIT</strong> </p>
  
  <p>I tried more extensive console logging for the API controller and once triggered, looks like it doesn't execute anything and skips to the ends, but then it picks back up and goes inside both User.findOne and user.save, yet looks like user.save is not working. </p>
  
  <p>Could it be that the server is not properly connected to the database? Is it there a way to determine if MongoDB methods are being used?</p>
  
  <p>Tried express logging as well:</p>
  
  <p><a href="https://i.stack.imgur.com/EIq4D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EIq4D.png" alt="enter image description here"></a></p>
  
  <p>And here is how the server is set up:</p>
  
  <pre><code>const express = require('express'),
        app = express(),
        logger = require('morgan'),
        config = require('./config/main'),
        mongoose = require('mongoose'),
        bodyParser = require('body-parser'),
        router = require('./router');
  
  mongoose.Promise = global.Promise;
  mongoose.connect(config.database);
  
  const server = app.listen(config.port);
  console.log('Your server is running on port ' + config.port + '.');
  
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  app.use(logger('dev'));
  
  app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "http://localhost:8080");
    res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, Access-Control-Allow-Credentials");
    res.header("Access-Control-Allow-Credentials", "true");
    next();
  })
  
  router(app);
  </code></pre>
  
  <p><strong>EDIT 2</strong></p>
  
  <p><a href="https://i.stack.imgur.com/0dN6B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0dN6B.png" alt="enter image description here"></a></p>