IdGenerator possibly not honoured on ReplaceOne upsert? (Works on InsertOne)

XMLWordPrintableJSON

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

      Hopefully I'm not misunderstanding something simple, but I have noticed I get different _id values generated in the database depending on whether I use InsertOne or ReplaceOne.
      I try to avoid any dependancy on MongoDB libraries etc, so the Id field in my objects is always a string. However, I want to use the ObjectId generation pattern. In much older versions of the driver, I was using the StringObjectIdGenerator, and am trying to do so now too.
      I'm using custom conventions to do my mapping (nothing strange in it, just that I use my own attributes to identify, for example, the ID field), and the important code looks like this:
      var cmm = memberMap.ClassMap;
      cmm.MapIdMember(memberMap.MemberInfo)
      .SetSerializer(new StringSerializer(BsonType.ObjectId).WithRepresentation(BsonType.String))
      .SetIgnoreIfDefault(true)
      .SetIdGenerator(StringObjectIdGenerator.Instance);

      If I call InsertOne, I get this:
      "_id" : "56a75e69e73e572dbc1b75c4"

      and if I call ReplaceOne (with a new document/no id set) I get this:
      "_id" : ObjectId("56a75e6a87dc53ded31754e8")

              Assignee:
              Unassigned
              Reporter:
              Kevin Versfeld
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: