[CSHARP-1080] unexpected change non id field name in BSON document Created: 01/Oct/14 Updated: 31/Mar/22 |
|
| Status: | Backlog |
| Project: | C# Driver |
| Component/s: | Serialization |
| Affects Version/s: | 1.9.2, 2.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Anatoliy Koperin | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I want to serialize following class:
I expected Id field to be serialized as "id", fix example: |
| Comments |
| Comment by Craig Wilson [ 04/Apr/16 ] | |||||||||||||||||||||||||||||
|
Hi Anatoliy, I understand where you are coming from. This certainly seems like a bug to me. However, it's not just as simple as adding release notes. I know from experience that users don't read those. Hence, this isn't an easy fix for us. I'm going to place this in the Planned but not Scheduled bucket and see if we can do something about it on our next major release (3.0). Until then, I think we are stuck. Craig | |||||||||||||||||||||||||||||
| Comment by Anatoliy Koperin [ 07/Oct/14 ] | |||||||||||||||||||||||||||||
|
In my case I wanted to insert a document in a database:
For mapping I used classes:
but a document appeared in the database was:
Such naming is unexpected to me. I found it because of the fact that the index which was expected on "optionalField.id" field did not appear. And here are some thoughts about the backward compability: During migration to the new version developers must add
| |||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 06/Oct/14 ] | |||||||||||||||||||||||||||||
|
I'm not sure what you mean. I'm not implying we break code. I'm saying that the easier thing to do here is to simply not "Find" and id member that has been marked as something other than an id. In other words, if a property called "Id" has a BsonElement("somethingElse") attribute on it, then it is obviously not the id member, so we shouldn't find it. This is going to be backwards breaking for some people, so the trick is to figure out whether people have done this and are living with it or if it is a legitimate bug. | |||||||||||||||||||||||||||||
| Comment by Anatoliy Koperin [ 06/Oct/14 ] | |||||||||||||||||||||||||||||
|
I think that as long as the code contains a method "public string FindIdMember (Type type)", it should work. | |||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 06/Oct/14 ] | |||||||||||||||||||||||||||||
|
Thanks for the PR: https://github.com/mongodb/mongo-csharp-driver/pull/190. This is a very interesting problem and one that doesn't affect a high majority of people. I think the better solution would be to fix the NamedIdMemberConvention to simply not map a property like this as the id member. See here: https://github.com/mongodb/mongo-csharp-driver/blob/v1.x/MongoDB.Bson/Serialization/Conventions/NamedIdMemberConvention.cs#L121. |