title: Can't insert documents in mongo using mongoose
body: <p>When I try to insert a document using the code below it creates an empty object instead of a document containing the correct data.</p>
  <p>The data is being passed correctly into the create method.
  <a href="https://i.stack.imgur.com/CKSuy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CKSuy.png" alt="enter image description here" /></a></p>
  <p>But after running it, an empty document gets inserted. No errors thrown.</p>
  <p><a href="https://i.stack.imgur.com/XiNQM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XiNQM.png" alt="enter image description here" /></a></p>
  <p>Here's the code.</p>
  <p><strong>Schema definition.</strong></p>
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  
  const User = new Schema({
      user_id: {
          type: String,
          unique: true
      },
      email: {
          type: String,
          unique: true,
          lowercase: true
      },
      password: String,
  });
  
  module.exports = { User }
  </code></pre>
  <p><strong>Init.</strong></p>
  <pre><code>const configuration = require(&quot;./configuration&quot;);
  var mongoose = require('mongoose');
  
  // Model declaration
  var { UserSchema, AdministratorSchema, TrailPointSchema } = require(&quot;./schemas&quot;)
  
  const UserModel = mongoose.model('User', UserSchema);
  const AdministratorModel = mongoose.model('Administrator', AdministratorSchema);
  const TrailPointModel = mongoose.model('TrailPoint', TrailPointSchema);
  
  async function connectToDbAsync() {
      configuration.logger.debug(&quot;attempting to connect with&quot;, configuration.databaseConnectionString);
      mongoose.set('useCreateIndex', true);
      await mongoose.connect(configuration.databaseConnectionString,
          {
              useNewUrlParser: true,
              useUnifiedTopology: true
          });
      configuration.logger.debug(&quot;connected&quot;);
  }
  
  module.exports = {
      connectToDbAsync, UserModel, AdministratorModel, TrailPointModel
  }
  </code></pre>
  <p><strong>Insertion.</strong></p>
  <pre><code>require(&quot;../typedef&quot;);
  const { logger } = require(&quot;../configuration&quot;);
  const { UserModel, TrailPointModel } = require(&quot;../init&quot;);
  const { v4: uuidv4 } = require('uuid');
  
  /**
   * 
   * @param {CreateUserDTO} user_data 
   */
  async function create_user(user_data) {
      try {
          /** Mapping the DTO-&gt;DO 
           * @type {User} 
           * */
          var userDO = {
              user_id: uuidv4(),
              email: user_data.email,
              password: user_data.password,
          }
          logger.debug(&quot;Mapping&quot;, user_data, userDO);
          logger.debug(&quot;Saving Object&quot;);
          var new_user = await UserModel.create(userDO);
          logger.debug(&quot;Saved &quot;, new_user);
          return new_user;
      } catch (e) {
          logger.error(&quot;Error saving User&quot;, arguments, userDO, e);
          return false;
      }
  }
  </code></pre>
  <p><strong>index</strong></p>
  <pre><code>var express = require(&quot;express&quot;);
  var bodyParser = require(&quot;body-parser&quot;);
  var { connectToDbAsync } = require(&quot;./init&quot;);
  const Controllers = require(&quot;./controllers&quot;)
  
  const app = express();
  app.use(bodyParser.json());
  app.use(express.static(&quot;app/public&quot;));
  connectToDbAsync().then(function () {
      Controllers.TrailController.register(app);
      Controllers.UserController.register(app);
      // app.get(&quot;*&quot;, function (req, res) {
      //     res.json(&quot;hello&quot;);
      // });
      app.listen(8080, () =&gt; console.log(&quot;App listening on port 8080!&quot;));
  });
  </code></pre>