Hi
I’m testing out a Realm app working on an incoming webhook post request.
I have an incoming webhook with a JSON payload which has a particular field that needs to be defined (or filtered?) and used to query the mongodb database collection I created. I want to see if this particular incoming value exists in the database and then return one of two responses.
As a starting point for the webhook function I used a mongodb tutorial based on an incoming webhook.
Then I set the find() method with the $exists: true query selector, and define the incoming payload field which is name.
For the response I have the response object method of setBody(body) with one of two responses.
When running the function on realm I get an error: error transpiling function source (Syntax error: exit status 1)
Please help, I’m a newbie still learning) and would love to make use of mongodb apps properly!
Many thanks, Andi
Here is the function I’m working on:
exports = async function(payload, response) {
const mongodb = context.services.get("mongodb-atlas");
const eventsdb = mongodb.db("mydatabase");
const eventscoll = eventsdb.collection("mycollection”);
const result= await eventscoll.find({“payload.name": {$exists: true}});
response.setBody("{"ok": true,"details”:”Found”}");
} else {
response.setBody("{"ok": false,"details":"Not found”}");
}
return { text: `searched` };
}