[CSHARP-965] Globally Set [BsonIgnoreExtraElements] Created: 03/May/14 Updated: 05/Apr/19 Resolved: 03/May/14 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Configuration |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Trivial - P5 |
| Reporter: | Liam Bateman [X] | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | bson, question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Description |
|
I'm new to MongoDB and the CSharp driver and I'm looking for a way to set [BsonIgnoreExtraElements] by default and add the ability for the developer to reverse the default.
Would this be something the team would consider? Happy to submit the pull request. |
| Comments |
| Comment by Craig Wilson [ 03/May/14 ] |
|
As for the second part, you can write your own custom attribute that implements IBsonClassMapAttribute. It will get picked up by the mapping system. You could then also write a convention that throws an exception when this attribute isn't found. I believe, in general, your approach is not the norm. It means that, by default, you're going to be losing data without knowing it. Therefore, we aren't going to provide these for you, but all the tools are there for you build them yourself. |
| Comment by Craig Wilson [ 03/May/14 ] |
|
This should be possible by registering a convention. In fact, we have a convention already built for this purpose: https://github.com/mongodb/mongo-csharp-driver/blob/v1.x/MongoDB.Bson/Serialization/Conventions/IgnoreExtraElementsConvention.cs You can see the documentation here for how to register it: http://docs.mongodb.org/ecosystem/tutorial/serialize-documents-with-the-csharp-driver/#conventions |
| Comment by Liam Bateman [X] [ 03/May/14 ] |
|
I've stumbled upon an older ticket that requests this, while not quite the same it does facilitate the ability to set it but it's per class. Is there a way to do for all classes all the time? |