I faced the same issue where response
object is undefined, it seems due to the specific way the response is set in MongoDB Atlas Functions.
It looks like MongoDB Atlas Functions use return
for setting the response.
Here’s how you can rewrite your code:
return {
status: 400,
body: { error: "Error" }
};
The documentation should be updated accordingly 