title: using mongoose population in Express
body: <p>There a lot of great examples in adding data in Schemas using population</p>
  
  <p>But how to use this in Express including evaluation existing data and error handling? I already create an user but now I want to add a log to a existing user. </p>
  
  <p>This is my Schema:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>const logSchema = new Schema({
      logTitle: String,
      postedBy: {
          type: mongoose.Schema.Types.ObjectId, ref: 'User'
      }
     });
  
  const userSchema = new Schema({
      
      _id: Schema.Types.ObjectId,
      firstName: {
          type: String,
          required: true
      } 
  });
  
  mongoose.model('User', userSchema);
  mongoose.model('Logs', logSchema);</code></pre>
  </div>
  </div>
  
  Despite all the good examples I lost my way. It 's hard to use the <a href="https://alexanderzeitler.com/articles/mongoose-referencing-schema-in-properties-and-arrays/" rel="nofollow noreferrer">nice examples</a> in good working Express code.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>const mongoose = require('mongoose')
  
  const Log1 = mongoose.model('Logs');
  
  
  const logCreate = function (req, res) {
      const userid = req.params.userid;
      Log1.create({
          logTitle: req.body.logTitle,
          postedBy: userid._id
      });
  
  module.exports = {logCreate
  };</code></pre>
  </div>
  </div>
  </p>
  
  <p>Do I first create a new log in 'Logs' and then evaluate the existing user? Can somebody give me a push in the right direction? Thanks in advance</p>