[JAVA-3501] Searching by UUID works incorrectly Created: 05/Nov/19 Updated: 27/Oct/23 Resolved: 06/Nov/19 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | JSON |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Anton Pozdeev | Assignee: | Jeffrey Yemin |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Now we use Spring Boot v.2.1.3 and faced with problem associated with searching by UUID in mongodb. Before(in Spring Boot v.1.5.8) we executed the next code:
and we got the correct result, But now this approach doesn't work I write:
and we get the error
I saw the ticket https://jira.spring.io/browse/DATAMONGO-2029, but It doesn't help us
I have created the ticket DATAMONGO-2397 , and now we use deprecated com.mongodb.util.JSON API, for example:
but it is deprecated API, can you add $uuid parsing to the JsonReader, as it was suggested in the comment |
| Comments |
| Comment by Jeffrey Yemin [ 06/Nov/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
For that you're going to need to write some code. You can parse that string, but for each $uuid in the JSON representation you'll end up with a nested document with a single field named "$uuid" whose value is the hex representation of the UUID. You'll need to recursively process that document, replacing each one matching that pattern with the corresponding UUID. It would look something like this:
I'm using BsonDocument instead of Document here because it's a bit easier to reason about its closed type system (Map<String, BsonValue> instead of Map<String, Object>). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Anton Pozdeev [ 06/Nov/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hello, thanks for your answer, but we have the next situation, maybe you know how to resolve it.
and previously, we set it into new BasicQuery("string") and it works correctly, but maybe you can suggest working approach for solving current problem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 05/Nov/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
We don't plan to re-introduce $uuid support to the Java driver's JSON parser. This was a non-standard addition in the old driver, and no other driver supports it. Instead, all drivers now support the same JSON representation, which is specified here. I can offer two alternatives, both illustrated in this example:
Be careful about the UUID representation, as cstrobl mentioned in DATAMONGO-2397 . There are incompatibilities with different drivers with regard to the byte order to which the UUID is serialized. That's why Example 1 explicitly specifies UuidRepresentation.JAVA_LEGACY |