RESTHeart issue with filters

I’ve been using RESTHeart on top of mongodb to have crud support with Mongodb’s REST interface. Its working fine when I’m not using any filter, however when I tried to apply filter with the HTTP GET request as provided in the documentation I got error with the stacktrace as provided below.

Request: http://127.0.0.1:8080/inBeta/donor?filter="{'name':'john'}"

14:15:49.373 [XNIO-1 task-1] ERROR c.s.restheart.handlers.ErrorHandler – error handling the request java.lang.ClassCastException: java.lang.String cannot be cast to org.bson.BSONObject at com.softinstigate.restheart.db.CollectionDAO.lambda$getCollectionData$45(CollectionDAO.java:178) ~[restheart.jar:0.9.7] at com.softinstigate.restheart.db.CollectionDAO$$Lambda$20/1288164368.accept(Unknown Source) ~[na:na] at java.util.ArrayDeque$DeqSpliterator.forEachRemaining(Unknown Source)~[na:1.8.0_31] at java.util.stream.ReferencePipeline$Head.forEach(Unknown Source) ~[na:1.8.0_31] at com.softinstigate.restheart.db.CollectionDAO.getCollectionData(CollectionDAO.java:177) ~[restheart.jar:0.9.7]

When I didn’t apply any filter its returning JSON object, however with filters its returning BSON object which RESTHeart is unable to convert as JSON response. Will appreciate any help or direction to look into the issue.

P.S. There is no tag for RESTHeart, so it would be helpful if someone could create a tag for the same.

Answer

Finally, issue resolved 🙂

I tried using other APIs provided in documentation and found that everything is working except filter and hence trying out the request using the below request:

http://127.0.0.1:8080/inBeta/donor?filter=%7B'username':'john'%7D

it worked. Hence the culprit is double quotes around filter query.

Leave a Reply

Your email address will not be published. Required fields are marked *