IMongoCollection<BsonValue> causes InsertOne to fail to insert "_id" member

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.4.4
    • Component/s: BSON
    • Environment:
      .Net Framework 4.5.2 on Windows 10
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      If I use IMongoCollection<BsonValue> rather than IMongoCollection<BsonDocument>, and use the InsertOne method to add a document which does not specify its own "_id" value, then InsertOne fails to insert the auto-generated "_id" member into the document object.

                      MongoClient myClient = new MongoDB.Driver.MongoClient(ConnectionConf);
                      var myDB = myClient.GetDatabase(DBName);
      
                      bool avoidBug = false;
      
                      if (avoidBug)
                      {
                          IMongoCollection<BsonDocument> myCollectionGood = myDB.GetCollection<BsonDocument>(CollectionName);
                          // InsertOne modifies doc as expected: it adds an "_id" member
                          myCollectionGood.InsertOne(doc);
                      }
                      else
                      {
                          IMongoCollection<BsonValue> myCollectionBad = myDB.GetCollection<BsonValue>(CollectionName);
                          // InsertOne fails to modify doc: it does not add the "_id" member
                          myCollectionBad.InsertOne(doc);
                      }
      

            Assignee:
            Robert Stam
            Reporter:
            Max Barraclough [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: