Hi, I’m working on an incoming webhook post request in Stitch and have a question about filtering the payload please – is it possible to filter the payload so that only a select field is inserted into the database collection?
I’ve used a mongodb youtube tutorial as the basis, which is great and uses an async/await function to insert the entire payload with “insertOne” – but I only want to insert a specific field (e.g. “name”:”John”) from the this payload into the database.
Many thanks, Andi
For POST webhook, you could retrieve a specific field as below:
const body = payload.body.text();
const document = EJSON.parse(body);
console.log("Only Name Field:", document.name);
Please note that this is the value (string), if you would like to insert this as a document you would need to create a document. i.e. {"name": document.name}.
For more information see Stitch: Incoming WebHooks
I’m a total newbie (as you can probably tell=) and trying out Mongo to use as nosql database for future applications.
Yes, I’d like to insert just the name field as a new document but I’m struggling to integrate {“name”: document.name} into that function, which is currently working really well to insert the entire payload as a new document.
I also have one last question please, to see how to make use of a GET webhook – where we only want to show the id field (not the _id):
Thank you so much Wan, that projection works really well for excluding a field, I’m going to dig deeper into the Stitch tutorials, looks like it has super potential for apps! Many thanks Andi