title: Mongoose Error: TypeError: Cannot read property 'exec' of undefined
body: <p>I'm trying to setup (this is my first attempt) a function that receives input, passes it through a function, then the results of that through a follow up.</p>
  
  <p>I'm getting the following error</p>
  
  <pre><code>TypeError: Cannot read property 'exec' of undefined
  </code></pre>
  
  <p>I've never used Promises before and I believe that's what I should be doing in this instance, I don't think I'm quite understanding how to structure things with the .exec and .then parts.</p>
  
  <pre><code>app.get('/api/gameobjects/:userid/:golng/:golat/:dist', (req, res) =&gt;
  {
      console.log("First part");
      GameObject.getNearGameObjects(req.params.golng, req.params.golat, req.params.dist)
      .exec((err, gameobject) =&gt;
      {
          if (err)
          {
              res.json(err);
          }
      })
      .then((gameobject) =&gt;
      {
          console.log("Third part");
          User.addGameObjectToUser(req.params.userid, gameobject)
      })
  });
  </code></pre>
  
  <p>EDIT:
  Code for the getNearGameObjects:</p>
  
  <pre><code>// Get Near Game Objects
  module.exports.getNearGameObjects = function( long, lat, dist, callback, limit )
  {
      var coords = [];
      coords[ 0 ] = long;
      coords[ 1 ] = lat;
  
      var query =
      { geometry: { $near: { "$geometry": { "type": "Point", "coordinates": [long, lat] }, $maxDistance: dist } } };
  
      GameObject.find( query, callback ).limit( limit );
  };
  </code></pre>
  
  <p>Code for the addGameObjectToUser</p>
  
  <pre><code>// Add object to user
  module.exports.addGameObjectToUser = function(id, gameobject, callback)
  {
      var query = { _id: id };
      User.findByIdAndUpdate( query, { "$addToSet" : { "inventory" : gameobject } } );
  };
  </code></pre>