[CSHARP-810] Save with polymorphic _id does not generate the query for the upsert correctly Created: 29/Aug/13  Updated: 25/Aug/15  Resolved: 02/Sep/13

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.8.2
Fix Version/s: 1.8.3

Type: Bug Priority: Major - P3
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

When Save can't determine for sure that the document is a new document (either because the idGenerator is null or because the id is not empty) it can't Insert the document so instead it upserts it.

But if the _id is polymorphic then the _id in the query generated for the Update is slightly wrong (it will be missing the _t field).

I believe the only way to safely generate the _id value is to serialize the entire document and extract the _id value from the result. The reason for this is because there may be custom serializers involved and we don't know how exactly they are going to end up representing the _id.

So Save has to serialize the document into an intermediate BsonDocument and extract the _id from that. It can save some amount of double serialization by then passing the BsonDocument to Update instead of the original document.



 Comments   
Comment by Githook User [ 25/Aug/15 ]

Author:

{u'name': u'rstam', u'email': u'robert@10gen.com'}

Message: CSHARP-810: Save should work with a polymorphic _id (or any custom serialization of an _id).
Branch: v1.8.x
https://github.com/mongodb/mongo-csharp-driver/commit/48aae83665d5d9320338613baffb1437450f8654

Comment by auto [ 25/Sep/13 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@10gen.com'}

Message: CSHARP-810: Save should work with a polymorphic _id (or any custom serialization of an _id).
Branch: v1.8.3
https://github.com/mongodb/mongo-csharp-driver/commit/48aae83665d5d9320338613baffb1437450f8654

Comment by auto [ 02/Sep/13 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@10gen.com'}

Message: CSHARP-810: Save should work with a polymorphic _id (or any custom serialization of an _id).
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/6af38da4b8271284bc71020df48fb8849af8ec50

Generated at Wed Feb 07 21:37:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.