:) I have run into an error using $function inside of an aggregation with MongoDB. I have an aggregation which should start with:
db.collection.aggregate([
{
$addFields: {
geohash: {
$function: {
body: function (coord1, coord2) {
let geohash = Geohash.encode(coord1, coord2);
return geohash
},
args: [
"$location.coordinates[0]",
"$location.coordinates[1]",
],
lang: "js",
},
},
},
},
])
However when i run the query it gives me this error: UnhandledPromiseRejectionWarning: MongoError: Invalid $addFields :: caused by :: The body function must be specified.
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. :)
Btw, as reference i used this doc: https://docs.mongodb.com/manual/reference/operator/aggregation/function/