[SERVER-2030] Better REST api query Created: 29/Oct/10  Updated: 07/Jul/17  Resolved: 07/Jul/17

Status: Closed
Project: Core Server
Component/s: HTTP Console
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Eliot Horowitz (Inactive) Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Done Votes: 6
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-9327 Core Simple Rest Interface to support... Closed
Duplicate
is duplicated by SERVER-9440 Trying to use the Simple Rest Interface Closed
Related
related to SERVER-12730 Full HTTP Rest interface Closed
Participants:

 Description   

Doing field by field isn't great so we should deprecate.

Should add

GET /db/collection
with

{x : 1 }

in the body



 Comments   
Comment by Radu Toader [ 10/Jul/15 ]

Hi,
This isn't fixed event I have the mongod version :
db version v2.4.9
Fri Jul 10 12:30:34.190 git version: nogitversion

It's not usefull if I cannot search for objects which have a string id / key and cannot find them.
also the url : "db/collection/id" does not work either, it returns all elements in my collection

Comment by Ivan Hristov [ 05/Dec/12 ]

Seems like there is not much of a motivation to improve the build-int REST API. Thus I would like to point that better REST API will definitely make MongoDB much easier to place in new projects as proof of concept and later switch to more powerful REST API. One great advantage of using MongoDB built-in API is that you can serve the content directly without having to bother with installing anything else bug MongoDB. In addition, it would be nice to have a MongoDB REST API module which we can install / enable if needed in contrast to have the logic built-in the core server. This will also facilitate contributing to this module only.

Comment by eh old1 [ 06/Jul/12 ]

Same question here.... I can't search for hex encoded _id values in other records -

http://127.0.0.1:28017/test/apps/?filter_room_id=4ff63758cf1d77f51c000000

Should be querying with

{ "room_id" : "4ff63758cf1d77f51c000000" }

but is truncating the ID:

{
"offset" : 0,
"rows": [

],

"total_rows" : 0 ,
"query" :

{ "room_id" : 4 }

,
"millis" : 0
}

Comment by Mike McWilliams [ 16/Mar/12 ]

If I'm trying to search for

{"sym":"500TEST"}

, how do I force the api to use quotes?
The following swallows "TEST" and uses 500 with no quotes:

http://localhost:28017/cache/entry/?filter_rec.sym=500TEST&limit=100&jsonp=?
Here's what's returned. (notice that 500TEST is converted to 500.
?({
"offset" : 0,
"rows": [

],

"total_rows" : 0 ,
"query" :

{ "rec.sym" : 500 }

,
"millis" : 156
}
)

Any help is greatly appreciated.

Comment by Remon van Vliet [ 08/Jan/11 ]

Speaking as someone that designs RESTful WS APIs for a living I would much appreciate if this could follow RESTful WS best practices as closely as possible. As such you should not use a POST for a query. A query should be implemented using the GET http verb, updates/upserts as PUT, inserts as POST, remove as DELETE, etc. Make sure URI design and HTTP status code usage is proper too please.

The query parameter as in your first suggestion seems a good start. URI composition should include database name, collection name and optionally field name, e.g. :

find(criteria, fields) : GET http(s)://[host]:[port]/[database]/[collection]/?criteria=[criteria]&fields=[fields]
count(criteria) : GET http(s)://[host]:[port]/[database]/[collection]/count?criteria=[criteria]
update(criteria, objNew, upsert, multiple) : PUT http(s)://[host]:[port]/[database]/[collection]/?criteria=[criteria]&upsert=[upsert]&multiple=[multiple] with objNew as the PUT body.

I would also suggest allowing the typical GET/PUT by id, in mongo's case the _id field so that :

find({_id: id}) : GET http(s)://[host]:[port]/[database]/[collection]/[id]
update({_id: id}, objNew) : PUT http(s)://[host]:[port]/[database]/[collection]/[id]

work as they should.

I'm happy to create a draft design if someone is interested.

Comment by Eliot Horowitz (Inactive) [ 06/Nov/10 ]

Correct.
We can't really improve the old method of querying as it doesn't work.
We're going to try to get this in 1.7, but the 1.7.x means if could slip.

Comment by Valery Khamenya [ 06/Nov/10 ]

Issue http://jira.mongodb.org/browse/SERVER-1800 is already closed and this one isn't yet implemented.
Does it mean that REST API isn't working as such in 1.6 and will not be until 1.7?

Generated at Thu Feb 08 02:58:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.