Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-810

Save with polymorphic _id does not generate the query for the upsert correctly

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.8.3
    • Affects Version/s: 1.8.2
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: