[CSHARP-672] Derived classes can't put timestamp in second position for server to automatically fill in the value Created: 01/Feb/13 Updated: 11/Mar/19 Resolved: 06/Apr/15 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.7 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Robert Stam | Assignee: | Robert Stam |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
If a document being saved to the server has an _id field in the first position and a zero valued BsonTimestamp (name doesn't matter) in the second position then the server fills in the value of the timestamp field automatically. But when using polymorphism with the C# driver this doesn't work for derived classes. Given the following classes:
when an instance of D is serialized (assuming the nominal type is C) the result is:
but since the driver inserted the _t discriminator field in the second position the server no longer sees the Timestamp field and doesn't fill the value in for you. The driver always puts the _t field in the second position so it doesn't have to scan too much of the document to find it, but in this case it should put it in the third position so the server can see the Timestamp in the second position. |
| Comments |
| Comment by Robert Stam [ 22/Sep/14 ] | |||||||||||||||||||||
|
Removed from Sprint 8. It's unclear whether we even want to implement this. The server team seems to recommend using an upsert with $currentDate instead. | |||||||||||||||||||||
| Comment by David Wagner [ 09/Aug/13 ] | |||||||||||||||||||||
|
This is not the only way to break the auto-generation of timestamps: see | |||||||||||||||||||||
| Comment by Kirill Davletkildeev [ 09/Mar/13 ] | |||||||||||||||||||||
|
Sounds perfectly reasonable. Still when the extra convention/attribute is not explicitly applied, discriminators should not change the timestamps autogeneration. | |||||||||||||||||||||
| Comment by Robert Stam [ 08/Mar/13 ] | |||||||||||||||||||||
|
We're rescheduling this ticket to 2.0. One reason is that it is not yet clear exactly how this should be supported. For example, it probably shouldn't be required for the auto timestamp field to be the first or second field in the class declaration, and it might even be defined in one of the subclasses. One possible implementation is to treat it similarly to how the _id field is treated, with attributes and conventions to identify the auto timestamp field. Here's a sample class declaration that illustrates how an attribute might be used to identify the auto timestamp field:
An instance of D serialized with a nominal type of C (so _t is required) might look like this:
| |||||||||||||||||||||
| Comment by Robert Stam [ 08/Mar/13 ] | |||||||||||||||||||||
|
Here's a link to the relevant server documentation: | |||||||||||||||||||||
| Comment by Kirill Davletkildeev [ 14/Feb/13 ] | |||||||||||||||||||||
|
This also should work, so that serializing with and without nominal type works similar:
|