[CSHARP-2516] Update field in document with value of other field in document Created: 12/Feb/19 Updated: 27/Oct/23 Resolved: 19/Mar/19 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | KevinBrok | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
We are working on an application which uses a MongoDB. Since the application is being used in Production we have to create Datamigration steps so the database cna be used in the newer version. A couple of times we moved a subdocument ot its own collection or we had to update the value of some documents to a different value which is also present in the document. What we do now is to get the document form the database. The set the value of the document with the new value, or we create an update command, and save it back to the database. What we would like to have is a way to update the value of a field with the value of another field in the same document. For example we have the following document:
We need to save the ClassificationId in the document instead of the whole Classification like this:
Maybe this can be done with something like this:
|
| Comments |
| Comment by Wan Bachtiar [ 06/Mar/19 ] | ||||||||||||||
Hi Kevin, This request is more relevant for the MongoDB server instead of MongoDB .NET/C# driver itself. What you've mentioned have been requested in As a temporary migration workaround, you could utilise $out aggregation stage to output a copy of the updated collection. For example:
Or, alternatively iterating through the whole collection to capture the document's value. Although this means reading all documents to the client. For example:
If you have further questions relating on the use of MongoDB .NET/C# driver please start a new discussion on mongodb-user group with relevant information. Regards, | ||||||||||||||
| Comment by KevinBrok [ 12/Feb/19 ] | ||||||||||||||
|
Wish I could fix the spell errors but turns out, I can't change the description. |