[CSHARP-2613] Update an entity field with data from another entity field Created: 21/May/19 Updated: 04/Jan/22 Resolved: 25/Jun/20 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | API |
| Affects Version/s: | 2.7.2 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Rick van Lieshout | Assignee: | Wan Bachtiar |
| Resolution: | Done | Votes: | 0 |
| Labels: | rfw | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Any |
||
| Description |
|
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: history: [{ 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..: |
| Comments |
| Comment by Rick van Lieshout [ 25/Jun/20 ] | ||||||||||||
|
You transitioned it to "Community answered", but what is the answer | ||||||||||||
| Comment by Wan Bachtiar [ 29/Oct/19 ] | ||||||||||||
You can do this with Update Using Aggregation Pipeline feature in MongoDB v4.2+. This allows you to use the expressive aggregation pipeline to update documents in the collection without knowing the value of `data`. For example, to automatically fetch the data field and pushed into history field :
Note that PipelineUpdateDefinition is available from MongoDB .NET/C# driver v2.9+. Please note that the CSHARP project is for reporting bugs or feature suggestions for the MongoDB .NET/C# driver. If you have follow-up questions on the use of the C# driver, please post a question on the MongoDB Community forums dot-net with the relevant information. |