I got a complex class (named ArticleData). Now, when i create a bsonDocument using the following code, the resulting bsonDocument automatically gets a document id (even though i try to set "_id" myself):
// bson document created from ArticleData object
var doc = articleData.ToBsonDocument();
doc["_id"] = "12345678";
articleCollection.InsertOne(doc);
I am not able to modify the class ArticleData in any way. Otherwise i could add a field '_id' and set this one to my custom id.
Does anyone know how i can set the id of the bsonDocument to a custom id?
The aim of my coding is to save that bsonDocument to my cosmosDb. In oder to be able to find my documents later i would like to query for my custom id (the unique article id).
Update: Real life example:
{
"ArticleID" : 9993,
"ArticleRevisionID" : 9993,
"StructureID" : 10000,
"StructureGroupID" : 10578,
"StructureGroupRevisionID" : 10578,
"ParentIdentifier" : "PS_1294.2",
"ModelIdentifier" : "PS_1294.2",
"ModelNrCatalog" : "1294.2",
"MaterialNumber" : "624341"
}
resulting bson document:
{
"_id" : ObjectId("5cd28ea84085af2d6c8318d2"),
"_t" : "MongoDB.Bson.BsonDocument, MongoDB.Bson",
"_v" : {
"_id" : "12345678"
"ArticleID" : 9993,
"ArticleRevisionID" : 9993,
"StructureID" : 10000,
"StructureGroupID" : 10578,
"StructureGroupRevisionID" : 10578,
"ParentIdentifier" : "PS_1294.2",
"ModelIdentifier" : "PS_1294.2",
"ModelNrCatalog" : "1294.2",
"MaterialNumber" : "624341"
}