Copy this code into your static utilities:
public static class Extensions
{
internal static bool IsNullOrEmpty(this BsonDocument bd, in string fieldName) => !bd.Contains(fieldName) || bd[fieldName].IsBsonNull;
internal static void AddElement(this BsonDocument bd, in string fieldName, in BsonValue value) => bd.Add(new BsonElement(fieldName, value));
internal static void AddNullableString(this BsonDocument bd, in string fieldName, in string value)
{
if (!string.IsNullOrWhiteSpace(value)) bd.Add(new BsonElement(fieldName, value));
}
internal static void AddNullable(this BsonDocument bd, in string fieldName, in BsonValue value)
{
if (value != null) bd.Add(new BsonElement(fieldName, value));
}
internal static void AddNullable(this BsonDocument bd, in string name, in int? value)
{
if (value != null && value != 0) bd.Add(new BsonElement(name, value));
}
internal static List<T> Map<T>(this Task<IAsyncCursor<BsonDocument>> bd, Func<BsonDocument, T> mapperFunction)
{
var data = bd.Result;
var dL = new List<T>();
while (data.MoveNext()) { foreach (var b in data.Current) { dL.Add(mapperFunction(b)); } }
return dL;
}