I’m trying to build out a function that will accept a payload of IDs, query the DB and return related documents.
At the moment I have these values hardcoded in my function, but the client calling this API is getting an empty object.
My function is:
exports = async function (payload, response) {
const collection = context.services.get("mongodb-atlas")
.db("mydb")
.collection("my collection");
const foundWantedCards = await collection.find(
{ card_id: { $in: [ "61ddf66c68ebbba1a4084e65", "61ddf5b768ebbba1a4fd2c33" ] }, forTrade:"Yes" }
);
return foundWantedCards
}
When I run this function within the editor I get a result
> result:
[
{
"_id": {
"$oid": "61e995ff2738954edae011ec"
},
"card_id": "61ddf5b768ebbba1a4fd2c33",
...
which is correct, but the value of FoundWantedCards
is empty. How should I return the result in the reponse?
Also, how should I access the payload that is sent in the POST request? I’ve tried via EJSON.parse(payload.body.text())
but again that is empty.
Any help much appreciated!