-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update server to allow extended Mongo query syntax #106
base: master
Are you sure you want to change the base?
Conversation
Having trouble with the below query @nescohen . Using your forked code. Any suggestions? Thanks! db.database.aggregate([{"$match": {"FileName": { "$in": [ /.paf/i]}}}, |
Hey @Mijobar, |
Thanks for reaching out @nescohen ! A picture/s worth a thousand words! =P Query from Robo3T: Works as expected Query from Grafana Using your Mongo Server: If I put quotes around what is in the array, (Ex: [" /.paf/i"] ) I don't get an error, but the query returns zero matches. Thanks! |
Hi
HI @nescohen Any thoughts on what the issue could be? Thanks! |
Hi @nescohen bumping this issue. Should I continue pursuing this issue or look to other avenues for a solution? Thanks for all your help thus far! Much appreciated! |
@Mijobar, sorry man I missed this. One thing you could try here is quoting the I don't know if you are familiar with javascript as well, but if you look into the source for the plugin, you can see the parsing steps taken. Some mongo queries may not be parsable into correct JSON which can make this process difficult. |
Hi @nescohen ! Thanks for getting back to me. Unfortunately, It's definitely, a JSON parsing issue. I am not familiar with JavaScript, do you mind just pointing me to the file/lines in the source that handles the JSON parsing? I'll then try to make a fix. Thanks! |
@Mijobar, One on line 13:
This line sets the http request parser to JSON mode, so I believe all incoming requests must be valid json. It may be possible to work around this by only decoding the request as a string. One on line 251:
This line actually parses the json into a query to send to mongo. It comes from this library: https://www.npmjs.com/package/mongodb-query-parser I think some of the awkwardness of this comes from the fact that these libraries or really expecting you to build a query inside of javascript, I think they were not really designed to turn a string sent by graphana into a query. I hope this helps! |
Hi @nescohen, thank you for this PR. I tried your fork because I was getting the This is my query, maybe can you find the bug? BTW, this query works great on the MongoDB shell. Thank you! Edit: I found the issue, but I don't know how to fix it. The issue is caused by the
|
@sy6sy2 Huh, that is interesting. If parenthesis are causing you problems, it is probably due to this line in
I am guessing that removing the parenthesis from these keys is not an option? Are you familiar with javascript? Unfortunately the solution probably involves going in and improving the logic for detecting the beginning and end of the query. It's not immediately obvious to me what is going wrong. |
Thanks for your answer. It's not a problem for me to remove parenthesis from the key strings so everything works fine for me 😉. |
Use mongodb parser and EJSON stringify to manipulate mongoDB query. This prevents some valid mongoDB queries from throwing JSON parsing errors.
Also in the same vain, fix bug whereby parenthesis in the JSON query cause parsing error.