[JAVA-2224] JsonReader does not support BsonRegularExpression Created: 14/Jun/16 Updated: 28/Jun/17 Resolved: 28/Jun/17 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | JSON |
| Affects Version/s: | 3.0.0 |
| Fix Version/s: | 3.5.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Guillaume Smet | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
When trying to parse the following query:
we end up with the following error:
This is due to the fact that JsonReader#visitRegularExpressionExtendedJson is not prepared to get directly an already parsed BsonRegularExpression. This is kinda annoying because we can't support this type of native query in Hibernate OGM. PR to come. |
| Comments |
| Comment by Jeffrey Yemin [ 16/Mar/17 ] | |||||||||||||||||
|
This will be fixed in scope of | |||||||||||||||||
| Comment by Guillaume Smet [ 15/Jun/16 ] | |||||||||||||||||
|
Hi Jeff, Sorry for the delay, been busy on other things. Note that the issue you mention in your last example already exists with the string syntax, it's not directly related to this patch. The fact is that I'm not even sure you're right on the way we should interpret it as, in strict mode, a BsonRegularExpression will be written like that at the end:
so if you rewrite the document to JSON in strict mode, you will end up with:
which is not supported by the server. I've spent some time on this issue but I didn't find any solution. I don't think there's a way to support this syntax. I did improve my patch though to deal with the { $regex: /test/, $options: 'ixms' }case correctly. Force pushed the PR. Thoughts? | |||||||||||||||||
| Comment by Jeffrey Yemin [ 14/Jun/16 ] | |||||||||||||||||
|
I see now. I had forgotten that $regex is serving double-duty: it's both the key that identifies a regular expression in MongoDB extended JSON, and it's a query operator. The problem is that JsonReader doesn't know anything about the query operators, so is trying to parse this string as extended JSON and so expects a string and not a pattern as the value of $regex. We have to be careful how we fix this. Take this case derived from the docs:
This should parse into something like:
If we just try to parse it the normal way but allow the value of $regex to use the shell's pattern syntax, we'll run into a problem once we hit the $eq. | |||||||||||||||||
| Comment by Guillaume Smet [ 14/Jun/16 ] | |||||||||||||||||
|
Hi Jeff, Thanks for your feedback. AFAICS, that's not what is documented in https://docs.mongodb.com/manual/reference/operator/query/regex/:
It seems that the syntax from the issue should be supported or the documentation updated. | |||||||||||||||||
| Comment by Jeffrey Yemin [ 14/Jun/16 ] | |||||||||||||||||
|
Hi Guillaume, This is by design. JsonReader will parse either MongoDB extended JSON, which would look like this:
or MongoDB shell-style "JSON", which would look like this
What you are attempting is a mix of the two, which is not supported anywhere as far as I know. From where are you getting the strings like the one in the description? | |||||||||||||||||
| Comment by Guillaume Smet [ 14/Jun/16 ] | |||||||||||||||||
|
Pull request: https://github.com/mongodb/mongo-java-driver/pull/355 |