quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.53k stars 2.61k forks source link

Issues when using Panache with Mongodb #30222

Open miguel-melo-impactzero opened 1 year ago

miguel-melo-impactzero commented 1 year ago

Describe the bug

Panache to query a Mongodb using the find(string,map) function does not work as expected.

Using the find(string,map) I provide a string as such "xyz.abc = :xyz.abc" and map with key "xyz.abc" and value "teste value" as string.

This find method needs to be dynamic depending on input from user.

Expected behavior

Panache is able to build the query and then perform it.

Actual behavior

Error is throw from Bson with message "org.bson.json.JsonParseException: JSON reader was expecting a value but found ':'."

How to Reproduce?

1) Create a Panache repository 2) Create a query string queryString 3) queryString = "xyz.abc = :xyz.abc"; 4) Create a Map<String,Object> queryParams 5) queryParams.put("xyz.abc","teste param"); 6) find(queryString, queryParams)

Output of uname -a or ver

No response

Output of java -version

1.8

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.15.Final

Build tool (ie. output of mvnw --version or gradlew --version)

mvnw

Additional information

No response

quarkus-bot[bot] commented 1 year ago

/cc @FroMage(panache), @evanchooly(mongodb), @loicmathieu(mongodb,panache)

loicmathieu commented 1 year ago

@miguel-melo-impactzero if I understand it correctly you want to pass a compex object as parameter and have the field (or the getter) or the object used to set the parameter ? This is not supported, we only support single objet as parameter (primitive, String, date), if an objet is passed as a parameter it's toString() method is called. You must pass each parameter values as separate parameter

miguel-melo-impactzero commented 1 year ago

@loicmathieu Hi, thanks for the response. Actually no, I am using wrapper classes and also have a list being passed to the parameter map and the way i implemented it works fine but using the normal way as I described causes a ParseException. I am using short 2-3 letter alias and it works fine but I had to build that workaround and it feels a bit disjointed.

As I have now I create the query string to be queryString = "xyz.abc = :aa" and the map has an entry ("aa", List<String) and it works fine, no complex object is on the param(which may or may not be a problem since I have objects on the db that I may need to filter with).

My best guess it that the param indicator on the query string cannot have some characters, in this case the dot(.), as it may have a different function for the parser or the query itself.

loicmathieu commented 1 year ago

@miguel-melo-impactzero I'm not sure but I didn't remember parsing the parameter names. Maybe if you can create a reproducer I could have a look

minhaz1217 commented 1 month ago

@loicmathieu I think I faced the same issue. I've created a project where I've generated the issue. Let me know if you need anything else.

https://github.com/minhaz1217/java-quarkus/tree/master/quarkus-parameter-map-issue

guildenstern70 commented 3 weeks ago

Same here. It appears that if a parameter is null, then the error 'JSON reader was expecting a value but found ':'' appears. Of course it would be nice that the passed parameters hashmap could contain nulls.