Mongo JSON filters in getRecordsByPost() creates entries rather than returning


#1

I’m working on a mobile app that makes use of angular-dreamfactory. I have a mongoDB table, representing events with a location and array of IDs of users who are attending. I want to retrieve entries in the table to which a particular user is signed up to, for which I want to use a mongo JSON filter. Based on the API documentation for mongo, I believe that my call should be as follows (for retrieving events user #1 is attending):

    DreamFactory.api.mongo.getRecordsByPost({"table_name":"Events", "body":{"filter": {"attending":{"$in": [1]}}}},
      function(data){
        console.log('Success!');
      },
      function(data){

      });

When I make use of getRecordsByPost in the live API, I’m successful in obtaining the records I want. However, when I make the call above, I don’t get any results, instead, a new entry is created in my table Events table, which looks as follows:

    {
      "_id": "1234cddad098654aaad3abbb",
      "filter": {
        "attending": []
      }
    }

If I try another filter, e.g. trying to retrieve all events taking place at Hollywood Bowl, using JSON filters, rather than the SQL ones, via

    DreamFactory.api.mongo.getRecordsByPost({"table_name":"Events", "body":{"filter":{"location":"Hollywood Bowl"}}}

Am I passing the filter incorrectly, or is there something else going on? I should mention that if I call DreamFactory.api.mongo.getRecords({"table_name":"Events"}), I successfully get the whole table as expected.


#2

So it sounds like its doing a POST instead of a GET.
Can you share the service definition for the mongo service ?


#3

Here are what I believe are the relevant lines from the service definition (plenty of lines already, the whole service definition is 2500+ lines, please let me know if you need me to post more):

"method": "POST",
          "summary": "getRecordsByPost() - Retrieve one or more records by posting necessary data.",
          "nickname": "getRecordsByPost",
          "notes": "Post data should be an array of records wrapped in a <b>record</b> element - including the identifying fields at a minimum, or a <b>filter</b> in the SQL or other appropriate formats with or without a replacement <b>params</b> array, or a list of <b>ids</b> in a string list or an array.<br/> Use the <b>fields</b> parameter to limit properties returned for each record. By default, all fields are returned for identified records. ",
          "type": "RecordsResponse",
          "event_name": [
            "{api_name}.{table_name}.select",
            "{api_name}.table_selected"
          ],
          "parameters": [
            {
              "name": "table_name",
              "description": "Name of the table to perform operations on.",
              "allowMultiple": false,
              "type": "string",
              "paramType": "path",
              "required": true
            },
            {
              "name": "body",
              "description": "Data containing name-value pairs of records to retrieve.",
              "allowMultiple": false,
              "type": "GetRecordsRequest",
              "paramType": "body",
              "required": true
            },

This came from setting up a MongoDB nosql connection, the database is hosted at MongoLab. Above the service definition, I get a message that the service definition is not editable.


#4

OK, so this is trying to tunnel, but the SDK doesn’t appear to know about it.
Can you add a “method”:“get” to your params your passing?
You could also just add a header called X-HTTP-METHOD and set it to “GET”.

I’ll dig deeper on this one.


#5

Thanks for the looking into this!

I tried adding "method":"get" to my params passing, but it didn’t seem to have an effect. Since I’m calling this from within an Angular controller, where would I have to put the X-HTTP-METHOD header?


#6

Let me update the SDK this morning, you shouldn’t have to do any of that, thats the point of the SDK ya know?


#7

This issue should be resolved with the latest 1.8 release of DreamFactory.