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

BsonDocumentWrapper BsonType is Document but AsBsonDocument throws

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.9
    • Affects Version/s: 1.8.3
    • Component/s: None
    • None

      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.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            nightroman Roman Kuzmin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: