Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-622

Add [MongoOldName("OldName")] attribute & updates to Linq provider

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.6.1
    • Component/s: None

      One common use-case for attempting migrations is for things like renaming fields. If you rename a property from `OldName` to `NewName`, the existing documents won't have been updated so `NewName` will typically be null.

      The defensive coding argument is to use [MongoExtraElements] attribute to fill a dictionary and update your CLR object accordingly.

      The issue with the defensive coding strategy is that you can't query against `NewName` until the object has been updated & saved. Most documents may take a while before they're upgraded, and some may never be upgraded. In the meantime, we would have to sprinkle all of our queries with `Query.OR(Query.EQ("NewName", "foo"), Query.EQ("OldName", "foo"))`.


      I propose that we solve this querying issue by updating the Linq driver to automatically do (x.NewName == "foo" || x.OldName == "foo") whenever a field has been renamed. To rename a field, I propose a [MongoOldName(<old-name>)] attribute.


      I believe that this case of renaming a field is very common. Due to the nature of Mongo, I also think it's best to implement this at the driver level.

            Assignee:
            Unassigned Unassigned
            Reporter:
            tkellogg Tim Kellogg
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: