[CSHARP-939] Revisit Dynamic DictionaryRepresentation Created: 21/Mar/14 Updated: 02/Apr/15 Resolved: 01/May/14 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Serialization |
| Affects Version/s: | 1.9 |
| Fix Version/s: | 2.0 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Robert Stam | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Major Change |
| Description |
|
We currently support the following dictionary representations:
The last 3 representations correspond to:
Each representation has its advantages. The first is probably the most natural representation and what most users would instinctively expect a Dictionary to be represented as. However, it can only be used when all they key values are strings and when the values of the strings are valid element names for a BSON document. The current default representation is Dynamic, which means that the serializer examines the keys and uses the Document representation if possible, and falls back to the ArrayOfArrays representation if not. Dynamic has pluses and minuses. On the plus side, serialization always succeeds and your Dictionary will be successfully saved to the database no matter what values the keys have. On the minus side, you will not have a consistent representation of your Dictionary values in your collection, because depending on the values of the keys one or the other representation will have been chosen. This is not a problem for round-tripping your Dictionary, but can be a huge problem if you need to write queries against your Dictionary values. The task in this ticket is to reconsider whether we should just remove the Dynamic representation or perhaps at least make it not be the default. It is tempting to make Document the default representation, but the problem with that is that if any of your keys have values that are not valid element names serialization will throw an exception. Is that acceptable? |
| Comments |
| Comment by Githook User [ 01/May/14 ] |
|
Author: {u'name': u'rstam', u'email': u'robert@10gen.com'}Message: |
| Comment by Robert Stam [ 29/Apr/14 ] |
|
We have made the decision to eliminate the Dynamic dictionary representation entirely, and default to Document. The good thing about this decision is that you can now count on a consistent representation in your database for Dictionary values, which means that you can more easily write queries against Dictionary values. The possible downside is that if you were serializing any Dictionaries where some of the key values were not valid BSON element names, you will now get runtime exceptions (instead of dynamically switching to ArrayOfArrays representation for just those cases). If your Dictionary has key values that are not valid element names, you should configure your serialization to use one of the other representations: ArrayOfArrays or ArrayOfDocuments. |