public Append ( String key, Object value ) : |
||
key | String | |
value | Object | |
return |
var document = new BsonDocument {{"name", "John"}}; document.Append("age", 30);
var document = new BsonDocument {{"name", "John"}}; document.Append(new BsonDocument { {"age", 30}, {"email", "[email protected]"} });
var document = new BsonDocument {{"name", "John"}}; document.Append("hobbies", new BsonArray {"hiking", "reading", "traveling"});In this example, we create a new document with a "name" field and set it to "John". Then we use the Append method to add an array field called "hobbies". We pass in a new BsonArray that contains three strings representing John's hobbies. The MongoDB.Driver package is used in these examples to provide a C# driver for interacting with MongoDB databases.