sql >> Base de Datos >  >> NoSQL >> MongoDB

Agregar matriz BSON a BsonDocument en MongoDB

Puede crear el documento anterior en C# con la siguiente instrucción:

var document = new BsonDocument {
    { "author", "joe" },
    { "title", "yet another blog post" },
    { "text", "here is the text..." },
    { "tags", new BsonArray { "example", "joe" } },
    { "comments", new BsonArray {
        new BsonDocument { { "author", "jim" }, { "comment", "I disagree" } },
        new BsonDocument { { "author", "nancy" }, { "comment", "Good post" } }
    }}
};

Puede probar si produjo el resultado correcto con:

var json = document.ToJson();