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

need a different way to accomplish BsonIgnoreExtraElements

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 1.7
    • Fix Version/s: None
    • Component/s: Feature Request
    • Labels:
      None
    • Environment:
      any

      Description

      If there are documents in Mongo, and the C# driver tries to create them into .NET classes that have "not enough" properties, the c# driver currently throws an exception. This is a problem in many cases.

      Someone has asked for this before, but was told that this was "by design" and that using the [BsonIgnoreExtraElements] attribute on the .NET class would solve the problem. It does, BUT.....

      I find this solution to be distasteful in the extreme because it ties the c# object model to Mongo. The model must have a dependency on the mongo dll that contains the attribute. This effectively prevents me from being able to use that attribute at all.

      Which means that migrating data is extremely painful when it involves removing properties from the model that have already been saved in Mongo.

      It would be MUCH better, if at the driver level, in the code, I could say something like:

      database.GetCollectionIgnoringExtraElements
      or
      collection.IgnoreExtraElementsWhenDeserializing
      or
      whatever.YouGetTheIdea()

      The whole point being - some way other than by adding a dependency on my model to Mongo, to achieve this goal. It would make migrations to the model MUCH EASIER. And would allow us to continue our adoption of Mongo.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: