var document = new BsonDocument(); var dictionary = new Dictionary{ { "A", 1 }, { "B", 2 }, { "C", 3 } }; document.AddRange(dictionary);
var document = new BsonDocument(); var nestedArray = new BsonArray() { new BsonDocument {{ "nestedA", 1 }}, new BsonDocument {{ "nestedB", 2 }}, new BsonDocument {{ "nestedC", 3 }} }; document.AddRange(new[] { new BsonElement("nestedArray", nestedArray) });In this example, a nested array containing multiple BsonDocument objects is added to the BsonDocument object. Both examples use the AddRange method to add multiple key-value pairs to BsonDocument object at once, improving code readability and reducing the number of method calls.