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

BsonDocumentWrapper BsonType is Document but AsBsonDocument throws

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 1.8.3
    • Fix Version/s: 1.9
    • Component/s: None
    • Labels:
      None

      Description

      My application analyses various documents created by the driver, including query and update documents from builders. I noticed the following problem. I was assuming that if BsonValue.BsonType is Document then it is valid to call AsBsonDocument on it. This is not true for BsonDocumentWrapper - its type is Document (set in the constructor) but AsBsonDocument is not overridden and throws "Cannot cast ...". Update builder Pull(query) creates such a wrapper, for example.

      If BsonDocumentWrapper wraps a document then AsBsonDocument should get this document. Otherwise it should not set its BsonType to Document or even be called a document wrapper.

      Currently an application dealing with generic documents, including created by the driver, has to perform checks for BsonDocumentWrapper type explicitly and unwrap it. This is neither effective nor natural, especially taking into account that BsonDocumentWrapper, I think, is mostly designed for internal driver needs.

        Attachments

          Activity

            People

            Assignee:
            rstam Robert Stam
            Reporter:
            nightroman Roman Kuzmin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: