I use MongoDB.DriversC # MVC in my application to communicate with the Mongodb database.
C # code
var client = new MongoClient("mongodb://localhost:27012");
var db = client.GetDatabase("Test_DB");
var collection = db.GetCollection<BsonDocument>("TestTable");
var tData = await collection.FindAsync(new BsonDocument(true));
MongoDB Data File

In the above image, you can see that I have several columns under the name DuplicateColwith different values. When I tried to read this data in c#using MongoDB.Driver, I got the following error:InvalidOperationException: Duplicate element name 'DuplicateCol'.
By inserting a duplicate element name, I used an AllowDuplicateNames=trueobject BsonDocumentas shown below. (It inserts the name of the repeating element without errors.)
BsonDocument obj = new BsonDocument();
obj.AllowDuplicateNames = true;
obj.Add("DuplicateCol", "Value_One");
obj.Add("propone", "newVal");
obj.Add("DuplicateCol", "Value_Two");
....
await collection.InsertOneAsync(obj);
Note: This scheme is required. I can’t change it.
Please provide me suggestions for fixing this problem. Any help would be greatly appreciated.
Thank.