Hello,
As the title suggests, the query runs fine in the console, but not when executed externally (through Postman).
Key Points:
- When logged, the moviesList is empty when externally triggered, but has data when in console.
- I have set up a default rule for the collection providing read/write access.
- It returns empty results externally, no errors caught.
Any help is appreciated. Thanks!
// This function is the endpoint's request handler.
exports = function({ query, headers, body}, response) {
// Data can be extracted from the request as follows:
let qry = {}
if(query.year) {
qry = {"year": {$eq: parseInt(query.year)}}
console.log("year: " + query.year);
} else if (query.title) {
qry = {"title": {$eq : query.title}}
console.log("title: " + query.title);
}
// Querying a mongodb service:
const doc = context.services.get("mongodb-atlas").db("sample_mflix").collection("movies");
const moviesList = doc.find(qry).limit(5).toArray();
let jsonList = JSON.stringify(moviesList);
// return jsonList;
if(response)
response.setBody(jsonList);
console.log(jsonList);
return moviesList;
};