SoftInstigate / restheart

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

Query a MongoDB with a get Request #275

Closed fdrsuisse closed 6 years ago

fdrsuisse commented 6 years ago

Good Morning, I have to query a MongoDB via a get to the following JSON

My current query: /sth_carouge?{'id':'sth/airno2_Foron_NO2_AirQualityObserved'}&hal=f doesn't work on the JSON:

{ "_id": "sth_carouge", "_size": 1480, "_total_pages": 370, "_returned": 4, "_type": "DB", "_embedded": { "rh:coll": [ { "id": "sth/airno2_Foron_NO2_AirQualityObserved", "_type": "COLLECTION", "_links": { "self": { "href": "/sthcarouge/sth/airno2_Foron_NO2_AirQualityObserved" } } }, { "id": "sth/airno2_Foron_NO2_AirQualityObserved.aggr", "_type": "COLLECTION", "_links": { "self": { "href": "/sthcarouge/sth/airno2_Foron_NO2_AirQualityObserved.aggr" } } }, { "id": "sth/airno2_Meyrin_NO2_AirQualityObserved", "_type": "COLLECTION", "_links": { "self": { "href": "/sthcarouge/sth/airno2_Meyrin_NO2_AirQualityObserved" } } }, { "id": "sth/airno2_Meyrin_NO2_AirQualityObserved.aggr", "_type": "COLLECTION", "_links": { "self": { "href": "/sthcarouge/sth/airno2_Meyrin_NO2_AirQualityObserved.aggr" } } } ] }, "_links": { "self": { "href": "/sth_carouge?pagesize=4&hal=f" }, "first": { "href": "/sth_carouge?pagesize=4&hal=f" }, "last": { "href": "/sth_carouge?page=370&pagesize=4&hal=f" }, "next": { "href": "/sth_carouge?page=2&pagesize=4&hal=f" }, "rh:root": { "href": "/" }, "rh:db": { "href": "/{dbname}", "templated": true }, "rh:coll": { "href": "/sth_carouge/{collname}", "templated": true }, "rh:bucket": { "href": "/sth_carouge/{bucketname}.files", "templated": true }, "rh:paging": { "href": "/sth_carouge{?page}{&pagesize}", "templated": true }, "curies": [ { "href": "http://restheart.org/curies/3.0/{rel}.html", "templated": true, "name": "rh" }, { "href": "http://restheart.org/curies/3.0/{rel}.html", "templated": true, "name": "rh" } ] } } Any help will be appreciated Best Regards, Francesco

ujibang commented 6 years ago

The query must be passed with the filter query parameter, ie /sth_carouge?filter={...}

fdrsuisse commented 6 years ago

Many thanks for your suggestion but the query :
"/sth_carouge?filter={'underscoreid':'sth/airno2_Foron_NO2_AirQualityObserved'}&hal=f " returns to me the same collection of the query: "/sthcarouge?hal=f"
During the copy and past of the JSON the underscore "underscore
" in the "underscore_id " and "sthunderscore" fields disappeared and I added 'underscore' to show you...

{ "_id": "sth_underscore/airno2_Foron_NO2_AirQualityObserved", "_type": "COLLECTION", "_links": { "self": { "href": "/sth_carouge/sth/airno2_Foron_NO2_AirQualityObserved" }

Probably I have to escape the underscore in "sth_/airno2".... Thanks in advance

ujibang commented 6 years ago

/sth_carouge is a db, correct?

the filter qparam applies to collection and document URIs (see http://restheart.org/learn/resource-uri/), for instance

GET /db/coll?filter={"a":1}

From your response, I see that you have a collection whose name contains / sth_underscore/airno2_Foron_NO2_AirQualityObserved

This is a problem, since it is not possible to distinguish the slash in the collection name from the slash used in the URI:

GET /sth_carouge/th_underscore/airno2_Foron_NO2_AirQualityObserved

will look for a document with _id airno2_Foron_NO2_AirQualityObserved in the th_underscore collection. see https://github.com/SoftInstigate/restheart/issues/177

only solution: don't use / in collection names

fdrsuisse commented 6 years ago

Hi "/sth_carouge" is the DB name. The collection contains a "/" in its name "sth_underscore/airno2_Foron_NO2_AirQualityObserved" I can't delete the / in the collection name, I am only an end user. If do I use another Rest tool such as Python EVE do you think will I have the same problem ? Many thanks for your answer