title: Page is displayed before async call finished? Output undefined. Mongoose.js
body: <p>My activity model has a property which is a reference to an ObjectId in the units table. The method works fine, in my opinion, as console logging <code>unit.name</code> logs correct name and also never hits the catch clause so there is no error in retrieval of the name, so I assume that it is being returned as well. </p>
  
  <p>Unfortunately, assuming <code>activity</code> is an instance of activities, calling <code>activity.unit_id</code> in my view returns undefined and my view shows undefined. All other properties are being printed properly:</p>
  
  <p><a href="https://i.stack.imgur.com/oOoL9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oOoL9.png" alt="enter image description here"></a></p>
  
  <p>My activity model's schema: </p>
  
  <pre><code>var activitySchema = new Schema({
      name: {
          type: String, 
          required: true
      },
      description: {
          type: String,
          required: true
      },
      pointsPerUnit: {
          type: Number,
          required: true
      },
      unit_id: {
          type: Schema.Types.ObjectId, 
          ref: 'Unit',
          get: function(unit_id) {
              Unit.findById(unit_id).then((unit) =&gt; {
                  console.log(unit.name)
                  return unit.name
              }).catch((e) =&gt; console.log(e));
          }
      }
  }); 
  </code></pre>
  
  <p>Here is what I am calling in my <code>.pug</code> file:</p>
  
  <pre><code>h2 All Activities
  
  each activity in activities
      p= "Name: " + activity.name
      p= "Description: " + activity.description
      p= "Points Per Unit of Excersise: " + activity.pointsPerUnit
      p= "Unit: " + activity.unit_id
      hr
  </code></pre>
  
  <p>I am also explicity logging <code>mongoose</code> queries to my console. Here's the execution from <code>mongoose</code>, which is also correct:</p>
  
  <pre><code>Mongoose: units.findOne({ _id: ObjectId("592679205a7b0e0c8fe7f47f") }, { fields: {} })
  Mongoose: units.findOne({ _id: ObjectId("592679205a7b0e0c8fe7f47f") }, { fields: {} })
  </code></pre>
  
  <p>Here is the controller code for the route:</p>
  
  <pre><code>/* GET users listing. */
  router.get('/new', function(req, res, next) {
      Activity.find({}).then((activities) =&gt; {
          res.render('activities/new', {activities});
      }); 
  });
  </code></pre>
  
  <p>Have spent two hours on this issue with no luck! Any help is appreciated.</p>