DSP MongoDB Filter

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.