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

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Gone away
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Serialization
    • None
    • 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

      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
            Reporter:
            yonatan ben avraham
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: