Details
Description
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);
|
}
|