mongodb - How to store an array of string in c#? -
either
hashset<string> aaa { get; set; } or
list<string> aaa { get; set; } or
string[] aaa { get; set; } also store as:
"aaa": { "0": "bbb", "1": "ccc" }, can't store as
"aaa": ["bbb", "ccc"] ?
the following code latest 10gen drivers produces document in format you're looking for:
public class mydocument { public int id { get; set; } public string[] aaa { get; set; } } class program { private static void main(string[] args) { var client = new mongoclient("mongodb://localhost"); var server = client.getserver(); var db = server.getdatabase("temp"); var coll = db.getcollection("mydocuments"); var mydoc = new mydocument { id = 1, aaa = new[] {"bbb", "ccc"} }; coll.save(mydoc); } } here resulting document:
/* 0 */ { "_id" : 1, "aaa" : [ "bbb", "ccc" ] } ilist , list work. have custom bson serialization annotations? have custom class maps?
Comments
Post a Comment