title: UnhandledPromiseRejectionWarning: MongoError: Invalid $addFields :: caused by :: The body function must be specified
body: <p>:)
  I have run into an error using $function inside of an aggregation with MongoDB. I have an aggregation which should start with:</p>
  <pre><code>db.collection.aggregate([
   {
     $addFields: {
        geohash: {
          $function: {
             body: function (coord1, coord2) {
               let geohash = Geohash.encode(coord1, coord2);
               return geohash
             },
            args: [
              &quot;$location.coordinates[0]&quot;,
              &quot;$location.coordinates[1]&quot;,
             ],
             lang: &quot;js&quot;,
           },
         },
      },
    },
  ])
  </code></pre>
  <p>However when i run the query it gives me this error: UnhandledPromiseRejectionWarning: MongoError: Invalid $addFields :: caused by :: The body function must be specified.</p>
  <p>I am on version 4.4 of Mongo and running this code inside a Node.Js function. Any help would be much appreciated. Thanks in forward. :)</p>
  <p>Btw, as reference i used this doc: <a href="https://docs.mongodb.com/manual/reference/operator/aggregation/function/" rel="nofollow noreferrer">https://docs.mongodb.com/manual/reference/operator/aggregation/function/</a></p>