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

Inserting an array into a child collection in MongoDB is omitting the _t Discriminator

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Serialization
    • Labels:
      None

      When using the insertOne function in the C# driver, in case we initialize an array with {{new[]

      {obj, obj, obj}

      }}.  The _t Discriminator is missing in the DB.

       

      for example:

      collection.InsertOne(new Parent { Children = new[] { new Child() } });
      

      will save to DB:

      {"_id":"5bf6aef6c0beccc414b70d45","Child":[{}]}
      

      The problem does not happen when using List

      collection.InsertOne(new Parent { Children = new List<IChild> { new Child() } });
      

      will insert into DB:

      {    "_id":"5bf6b074c0beccc414b70dc2",    "Children":[{"_t":"Child"}]}
      

      for further information please check this StackOverflow question:

      https://stackoverflow.com/questions/53432370/inserting-an-array-into-a-child-collection-in-mongodb-is-omitting-the-t-discrim/53544804?noredirect=1#comment94153188_53544804

            Assignee:
            Unassigned Unassigned
            Reporter:
            yonbav yonatan ben avraham
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: