DSP MongoDB Filter

Hi,
I’m working on IoT Project where devices send data to DSP Cloud. I have connected MongoDB database “admin’ to DSP an has named ThingsCloud. I’m able to POST and GET Records, But I have problems in using filter to get data from specific device id.
Here is my problem statement
I have several devices, like device=40, device=50 posting data to cloud and I want to filter data’s from individual devices. I have “deviceid”:”##" as identifier in the JSON to recognize data from different devices.
I need to get records which has deviceid: 50, inserted from today morning.

Below is my JSON that is being inserted

http://i.imgur.com/hAY3svo

I’m using getRecordsByFilter() api to get all the records which matches my query. Basically I want all the records with the Deviceid = 50

http://imgur.com/rMyLbav

If I execute this, I get nothing, even though I have around 20 records with Deviceid = 50. It gives response code = 500.

App Name: ThingsCloud
MongoDB Name: admin
Table Name: data

Kindly help as I’m stuck

I don’t think you need to use the db.data.find syntax within the filter parameter field. I believe the MongoDB driver takes care of the syntax for you.

In my case, I have a collection called “collection” that contains three records with one field, called “field”, like so:

Request URL

http://dsp:80/rest/mongodb/collection

Response Body

{
  "record": [
    {
      "_id": "55ad4045ddd2fc80058b4567",
      "field": "james"
    },
    {
      "_id": "55ad405dddd2fce11d8b4567",
      "field": "john"
    },
    {
      "_id": "55ad4062ddd2fce11d8b4568",
      "field": "peter"
    }
  ]
}

I can filter on the contents of “field” by simply filling in the SQL WHERE clause as it would be in a normal SQL filter parameter:

The above filter syntax returns the following response:

Request URL

http://dsp:80/rest/mongodb/collection?filter=field%3D%22john%22

Response Body

{
  "record": [
    {
      "_id": "55ad405dddd2fce11d8b4567",
      "field": "john"
    }
  ]
}

As the description of the “filter” field indicates, it’s expecting simple SQL-style filter parameters. The translation to MongoDB filtration is performed by DreamFactory. If you prefer to write queries in Mongo’s JSON query document format, you can simply include your formatted query as a POSTed payload. Lee’s blog on MongoDB outlines this.