Hi,
I’m new to MongoDB and have been working through the below example with AppGyver.
[Realm Serverless Platform Integration with No-Code Composer from AppGyver | MongoDB](Realm Serverless platform integration with No-Code Composer from AppGyver - By Pavel Duchovny and Harri Sarsa)
Everything has gone great, except when I got to the section to get a list of movies using the GetMovies webhook. The sample code as documented is below…
/*
This API searches movies from db("sample_mflix").collection("movies") using Atlas Search aggregation
*/
exports = async function(payload, response) {
// Extract, the search query param
const {Search} = payload.query;
var filter;
// Get the collection object
const movies = await context.services.get("mongodb-atlas").db("sample_mflix").collection("movies");
var doc = [];
console.log(`ID ${Search}`);
// If Search term is not empty use atlas search $search operator
if (Search !== "")
{
filter = [{
'$search': {
'text': {
'path': ['title', 'plot','fullplot','generes'],
'query': Search,
'fuzzy': {}
}
}
},{"$limit" : 100}];
doc = await movies.aggregate(filter).toArray();
}
else
{
// If no Search term provided return first found 100 results
doc = await movies.aggregate([{"$limit" : 100}]).toArray();
}
// Return the found documents through the response object
response.setBody(JSON.stringify(doc));
response.setStatusCode(200);
};
The problem I am having is that payload.query always is an empty string - so nothing is returned.
I have been using Postman to call the webhook, to remove AppGyver from the equation and the result returned is always an empty array .
This is the request I make…
https://ap-southeast-2.aws.webhooks.mongodb-realm.com/api/client/v2.0/app/moviesapp-zcjuo/service/MoviesAPI/incoming_webhook/GetMovies?Search=Horse
I’ve done a fair bit of reading, but can’t figure out why it’s not working.
This is the log output.
Logs:
[
"ID "
]
Function Call Location:
AU
Query Arguments:
{
"Search": ""
}
Headers:
{
"Content-Type": [
"application/json"
],
"Accept": [
"*/*"
],
"Accept-Encoding": [
"gzip, deflate, br"
],
"Accept-Language": [
"en-GB"
],
"X-Forwarded-Proto": [
"https"
],
"X-Cluster-Client-Ip": [
"111.11.11.11"
],
"User-Agent": [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_16_0) AppleWebKit/537.36 (KHTML, like Gecko) AppGyver/1.8.1 Chrome/78.0.3904.130 Electron/7.1.14 Safari/537.36"
],
"Sec-Fetch-Site": [
"cross-site"
],
"Sec-Fetch-Mode": [
"cors"
],
"X-Forwarded-For": [
"111.11.11.11"
],
"X-Envoy-External-Address": [
"111.11.11.11"
],
"X-Request-Id": [
"ecf6ed27-b79e-4b40-8d4a-56cd1829835f"
]
}
Compute Used:
24193082 bytes•ms
Remote IP Address:
111.11.11.11
Rule Performance Metrics:
{
"sample_mflix.movies": {
"no_matching_role": 0
}
}
It may be that MongoDB Realm has changed which is why the code doesn’t work, as this article was written about a year ago now.
If anyone can see the issue, I’d love to know. Being able to return a set of results is a pretty fundamental requirement to my (or any) app!
Thanks