I extract data from mongoDB successfully as List<mongobisondocument. the dataset some if empty values that causes error when write in to the datatable (Using add data column)
Please assist on how to replace empty values in List<mongobisondocument with any other value
You can loop through the list and check each document for empty values in its properties. If an empty value is found, you can replace it with a default value of your choice.
Please try implementing the following code snippet & let us know:
List<MongoDB.Bson.BsonDocument> documents = GetDocumentsFromMongoDB();
string defaultValue = "N/A";
foreach (var document in documents)
{
foreach (var element in document.Elements)
{
if (element.Value == MongoDB.Bson.BsonNull.Value || element.Value == "")
{
document.Set(element.Name, defaultValue);
}
}
}