[CSHARP-1024] Provide a way to allow alternate field names to ease schema migration Created: 04/Aug/14  Updated: 31/Mar/22

Status: Backlog
Project: C# Driver
Component/s: BSON
Affects Version/s: 1.9.2
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Vincent Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CSHARP-622 Add [MongoOldName("OldName")] attribu... Closed
Backwards Compatibility: Fully Compatible

 Description   

It's currently a total pain when we want to make a schema migration (shortening a field name for example). We need to mark the old property with {{ [BsonIgnoreIfNull] }} (or {{ ...IfDefault] }} and that properties set the new property we'd like to use instead and make the old property always return null (or default). Not clean at all and difficult to read.

To my opinion a much cleaner way would be to have a custom attribute like:
{{ [BsonAllowedAlternateNames("name1",123,etc.)] }} that would allow that property to be set by those element names, only affecting deserialization of the documents (bson => c#) and not serialization.

I realize it could lead to deserialization conflicts: those conflicts could be managed by attribute settings (like "takes precedence" or so), and/or by a custom resolve method.



 Comments   
Comment by Vincent [ 05/Aug/14 ]

Thanks, that's good to hear I've to admit I like it a lot too...

Comment by Craig Wilson [ 05/Aug/14 ]

I like this idea a lot. I've added it to the planned but not schedule bucket as we are in feature freeze for our next 2.0 release.

Generated at Wed Feb 07 21:38:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.