簡體   English   中英

MongoDB將數組添加到BsonDocument

[英]MongoDB add array to BsonDocument

我正在嘗試使用C#驅動程序在mongodb文檔中添加字段。

我正在創建一個文檔。

BsonDocument document = new BsonDocument();

並添加

document.Add(name, value); // here name and value both are string

但我不確定如何在這種情況下添加數組

document.Add(name, values); // here values is List<string> document.Add(name, values); // here values is List<string>

例如document.Add(skills, [C++, Java, C#]);

請在這件事上給予我幫助

如果您正在使用List<string>

var skills = new List<string> {"C++", "Java", "C#"};
document.Add("skills", new BsonArray(skills));

或者,更簡單:

document.Add("skills", new BsonArray { "C++", "Java", "C#" } );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM