[CSHARP-3179] FilterDefinition don't respect GuidRepresentation Created: 11/Aug/20 Updated: 22/Jun/22 |
|
| Status: | Backlog |
| Project: | C# Driver |
| Component/s: | API |
| Affects Version/s: | 2.11.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Hervé TINANT | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 2 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
dotnet core 3.1 on Linux and Windows |
||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||
| Description |
|
I replace BsonDefaults.GuidRepresentation = GuidRepresentation.Standard; by BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard)); to set all my app use Standard representation,
But if I do Builders<MyEntity>.Filter.Eq("_id", myGuid);, the filter is translated with CSUUID(...) in place of UUID(...).
In more largest case, how I can specify Guid representation with this type of filter ? |
| Comments |
| Comment by Robert Stam [ 11/Sep/20 ] | ||||||||||||||||||||||||||||||
|
Currently V2 mode is the default in order to maintain backward compatibility. If you want to use the new V3 mode you have to opt in to it. BsonDefaults.GuidRepresentationMode is marked as deprecated because in a future version of the driver we will remove support for V2 mode and at that point we will also remove the GuidRepresentationMode property from BsonDefaults. | ||||||||||||||||||||||||||||||
| Comment by Chad Kreimendahl [ 04/Sep/20 ] | ||||||||||||||||||||||||||||||
|
Is V3 default? It seems when you set BsonDefaults that GuidRepresentationMode is flagged as deprecated, also. | ||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 28/Aug/20 ] | ||||||||||||||||||||||||||||||
|
While investigating further I have confirmed that even though the FilterDefinition is being rendered correctly, unless you work around it the Guid in the rendered filter will be coerced to the `BsonDefaults.GuidRepresentation` when the rendered filter is written to the wire, so there is in fact an issue. The easiest workaround is to use the new V3 GuidRepresentationMode. In fact, I would recommend that anyone using Guids investigate switching to the new V3 GuidRepresentationMode. | ||||||||||||||||||||||||||||||
| Comment by Hervé TINANT [ 14/Aug/20 ] | ||||||||||||||||||||||||||||||
|
In fact what I see is ToJson result, but I inspect it just because some test of my repository class don't pass, so ... Anyway, I will perform some test next week with BsonDefaults.GuidRepresentation = GuidRepresentation.Unspecified; and come back to you. | ||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 13/Aug/20 ] | ||||||||||||||||||||||||||||||
|
You could also consider trying out the new V3 GuidRepresentation mode. I also tested with:
| ||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 13/Aug/20 ] | ||||||||||||||||||||||||||||||
|
I tried to reproduce this but it looks like the `Filter` builder is working correctly. Here's my test program:
and the output is:
I suspect what you are seeing is the output of ToJson (which is also what you will see in the debugger because ToString calls ToJson) and ToJson continues to do what it always did in V2 GuidRepresentationMode which includes translating Guids to CSUUID format. To get ToJson to not do any Guid translations add the following line to the beginning of your program:
Let me know if this does not address your question or if you have follow up questions. | ||||||||||||||||||||||||||||||
| Comment by Hervé TINANT [ 11/Aug/20 ] | ||||||||||||||||||||||||||||||
|
For now, I keep BsonDefaults.GuidRepresentation = GuidRepresentation.Standard; and it's work so not really urgent |