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

Discriminator incorrect when using "OfType<>"

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 2.12.0
    • 2.4.4
    • Serialization
    • None

    Description

      When using OfType<TDerived> on a collection, the "ofTypeFilter" filter of the returned IFilteredMongoCollection<TDerivedDocument> does not generate a correct discriminator.

      Consider this:

      [BsonDiscriminator(RootClass = true)]
      class A {}
      class B : A {}
      

      var collection = database.GetCollection<A>("users").OfType<B>();
      

      The "collection" variable will be of type IFilteredMongoCollection<B> with an internal "ofTypeFilter" generating a discriminator looking like this:

      { "_t" : "B" }
      

      where it should have looked like this:

      { "_t" : ["A", "B"] }
      

      Ultimately this leads to a problem when using "upsert". Since parts of the document inserted comes from the filter, the discriminator does so as well. Since it is incorrect rendered, it leads to document in mongo with a wrong discriminator.

      Attached is a small program that reveals the problem.

      Attachments

        Activity

          People

            boris.dogadov@mongodb.com Boris Dogadov
            marloe Martin Lobger
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: