BsonDocument.DeepClone() fails on documents with duplicate element names

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor - P4
    • 2.25.0
    • Affects Version/s: 2.7.0
    • Component/s: BSON
    • None
    • Environment:
      All
    • None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      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.

       

              Assignee:
              Boris Dogadov
              Reporter:
              Adam Milazzo
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: