The following code fails:
var doc = new BsonDocument() { AllowDuplicateNames = true };
doc.Add("a", 1);
doc.Add("a", 2);
var doc2 = doc.DeepClone();
This is because DeepClone does:
{{ BsonDocument clone = new BsonDocument();}}
{{ foreach (BsonElement element in _elements)}}
{{ {}}
clone.Add(element.DeepClone());
{{ }}}
{{ return clone;}}
Changing the first line to:
BsonDocument clone = new BsonDocument() { AllowDuplicateNames = AllowDuplicateNames };
fixes the problem.
- is related to
-
CSHARP-2354 BsonDocument constructor fails to copy documents with duplicate element names
- Closed