SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

Query a MongoDB collection #318

Closed fdrsuisse closed 5 years ago

fdrsuisse commented 5 years ago

Hi according to your documentation https://restheart.org/learn/resource-uri/ I can query a collections and documents URI: GET /db/coll?filter={"a":1} When I execute this request: 1)curl -i "http://db_url/db/collection?filter={'entityId':'1044'}" -u admin:changeit -H 'Content-Type:application/json' 2)curl -i 'http://db_url/db/collection?filter={"entityId":"1044"}' -u admin:changeit -H 'Content-Type:application/json' I obtain {"_exceptions":[{"exception":"org.bson.json.JsonParseException","exception message":"JSON reader was expecting a name but found ':'."}] The JSON(http://db_url/db/collection?count) is : {"_embedded":[{"_id":{"$oid":"5b758d88a3266706472cd4cd"},"recvTime":{"$date":1534430600815},"entityId":"1044","entityType":"parking","batteryLevel":"81","confidence":"HIGH","dateTime":"2018-08-16T16:22:01Z","lastDateTime":"2018-08-07T05:09:33Z","lastStatus":"FREE","latitude":"46.187681196","longitude":"6.140844847","magneticStatus":"OCCUPIED","rssi":"-110","softwareVersion":"21","sonicStatus":"OCCUPIED","spreadingFactor":"9","status":"ONLINE","temperature":"15","triggerType":"PERIODIC"} Thanks in advance, Francesco

mkjsix commented 5 years ago

That doc is generic and not specific to curl. Try something like:

$ curl -i  -u "admin:changeit" -H "key:demo Content-Type:application/json" -G \
--data-urlencode "filter={'entityId':'1044'}" http://db_url/db/collection

Have a look at https://restheart.org/try for examples with curl.

We suggest to install httpie, which has a less cumbersome syntax than curl.

ujibang commented 5 years ago

this is an issue with curl URL globbing parser, just do as follows

curl -g -i "http://db_url/db/collection?filter={'entityId':'1044'}" -u admin:changeit -H 'Content-Type:application/json'

-g/--globoff This option switches off the "URL globbing parser". When you set this option, you can specify URLs that contain the letters {}[] without having them being interpreted by curl itself. Note that these letters are not normal legal URL contents but they should be encoded according to the URI standard.

fdrsuisse commented 5 years ago

Hi I very appreciated your suggestions it works. You can close the issue. Best Regards, Francesco