[CSHARP-1243] Set Value to a BsonElement Created: 20/Apr/15 Updated: 05/Apr/19 Resolved: 27/Apr/15 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | BSON, Documentation, Serialization |
| Affects Version/s: | 2.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Blocker - P1 |
| Reporter: | petrica [X] | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | driver, question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
|
||
| Description |
|
Hi, |
| Comments |
| Comment by Robert Stam [ 20/Apr/15 ] | ||||
|
In the 2.0 version of the driver the BsonElement class was changed to an immutable struct. The two primary reasons this was done were: 1. Performance, structs create less pressure on the garbage collector You can probably change your code to just replace the value of your date variable with an entire new BsonElement instance:
Although depending on where the value of your date variable came from you might have been depending on mutating the existing instance. For example, the following code will no longer behave the same as it did in 1.10:
In 2.0 this code only modifies the date variable, leaving the original document unchanged. If your intent is to update the "date" field inside a document write this instead:
| ||||
| Comment by Craig Wilson [ 20/Apr/15 ] | ||||
|
Hi Petrica, Questions like this are better asked in our public forums: https://groups.google.com/forum/?pli=1#!forum/mongodb-csharp or on stackoverflow. However, since we are here... To answer this question, we need a bit more information. What is the type of your "date" variable? Craig |