SoftInstigate / restheart

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

No way to cast to ObjectID in `filter` #159

Closed brodeuralexis closed 7 years ago

brodeuralexis commented 7 years ago

I am trying to implement Seek Pagination for a client using the document's autogenerated _ids.

This is the request I initially tried :

GET /data-cache/test?filter={"_id": { "$oid": { "$gt": "57fd2d37c9e77c0007e48008" } }}&pagesize=10 HTTP/1.1
Host: restheart

Alas, it returns a 400 with a java.lang.ClassCastException.

After digging through the source code, I understand that a BsonDocument is created from the filter query parameter and then sent to MongoDB directly.

What I need is a way to specifie that a key in my filter property is an ObjectId like adding a query parameter (oid in this example) :

GET /data/cache/test/?filter={"_id": { "$gt": "57fd2d37c9e77c0007e48008" }}&pagesize=10&oid=["_id.$gt"] HTTP/1.1
Host: restheart

Logic to cover this use case could be added to the RequestContext.getFiltersDocument method.

If such a change is out of scope, I will simply have to fall back to the native MongoDB driver.

ujibang commented 7 years ago

simply invert the order of $gt and $oid

GET /data-cache/test?filter={"_id": { "$gt": { "$oid": "57fd2d37c9e77c0007e48008" } }}&pagesize=10
brodeuralexis commented 7 years ago

This works, thank you.

I'll be leaving this link here for reference : https://docs.mongodb.com/manual/reference/mongodb-extended-json/#data_oid