MongoDB Realm with Composer - Search not working


I’m new to both AppGyver and MongoDB and loving what I see.

I have been working through the below example.

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"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','genres'],
              'query': Search,
              'fuzzy': {}
      },{"$limit" : 100}];
       doc = await movies.aggregate(filter).toArray();
       // 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


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…

I’ve done a fair bit of reading, but can’t figure out why it’s not working.

This is the log output.

  "ID "
Function Call Location:
Query Arguments:
  "Search": ""
  "Content-Type": [
  "Accept": [
  "Accept-Encoding": [
    "gzip, deflate, br"
  "Accept-Language": [
  "X-Forwarded-Proto": [
  "X-Cluster-Client-Ip": [
  "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": [
  "Sec-Fetch-Mode": [
  "X-Forwarded-For": [
  "X-Envoy-External-Address": [
  "X-Request-Id": [
Compute Used:
24193082 bytes•ms
Remote IP Address:
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!


I’ve figured out what the problem was. I needed to Create an Atlas Search Index using the Atlas UI as documented here…

Until I did this, it would always return an empty array (if a non-empty search param was passed) and I also noticed that sometimes the queryParam I passed was not even received. It appears to be working perfectly now.

Also note - there’s a typo in this string…

'path': ['title', 'plot','fullplot','generes'],

‘generes’ is the wrong spelling… should be 'genres'.