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

Update an entity field with data from another entity field

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.7.2
    • Component/s: API
    • Environment:
      Any

      In short. I want to be able to issue a `.Set` and reference the existing document(/entity) for fields.

      I posted a question on [StackOverflow|https://stackoverflow.com/questions/56217554/mongodb-c-sharp-driver-update-an-entity-field-with-data-from-another-entity-fie] which goes like this:
      My model looks something like this:
       data: {
      field1 :"1"
      },

      history: [{
      field1 :"0"
      }]
      {{}}

      Now I want to create an update definition which takes the current object in "data" and inserts it into the "history" array.

      I know how to do this with absolute values..:
       var updateDef = Builders<Entity>.Update.Push(x => x.History, historyObject);
      updateDef = updateDef.Set(x => x.Data, newDataModel);
      The problem is that I want the "historyObject" to be automatically gotten from the current document's "data" field.

            Assignee:
            wan.bachtiar@mongodb.com Wan Bachtiar
            Reporter:
            mastermindzh Rick van Lieshout
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: