_t Discriminator is lost when using ReplaceOneAsync

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Minor - P4
    • None
    • Affects Version/s: 2.7.3
    • Component/s: Serialization
    • None
    • Environment:
      Visual Studio 2017, C#
    • 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

      I am using the following generic code to replace a document with an updated version

       public async Task UpdateAsync<T>(T model, string collectionName) {
       var filter = Builders<T>.Filter.Eq("_id", model.Id);
       await database.GetCollection<T>(collectionName).ReplaceOneAsync(filter, model);
      }
      

      The documents are stored with a _t discriminator like that:

      { "_id" : "5c7fb949d0c890000179bb46", "_t" : "Type",  ....
      

      After using ReplaceOneAsync the _t discriminator is removed from the file in the database.
      I guess a workaround would be to manually cast model as the specific type and update all fields, which would result in _t not getting modified. (The question is if that is less performing.)

            Assignee:
            James Kovacs
            Reporter:
            Martin Schneider
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: