c# - Insert new document in nested documents in Mongodb -


i newbie in mongodb, please see models below.

public class technology {     public technology()     {         productgroups = new list<productgroup>();     }      [bsonrepresentation(bsontype.objectid)]     public objectid _id { get; set; }      public string name { get; set; }      public ienumerable<productgroup> productgroups { get; set; } }  public class productgroup {      [bsonrepresentation(bsontype.objectid)]     public objectid _id { get; set; }      public string name { get; set; }  } 

now data shows below.

enter image description here

i try add productgroup ( it's bsondocument collection)

collection in technology.

could please help

change model of technology

[bsonelementattribute("productgroups")] public ilist<productgroup> productgroups{ get; set; } 

then,

var productgroup = new bsondocument().add("_id", productgroup_id).add("name", name);  var technologies = database.getcollection("technology"); var technology = technologies.findonebyid(objectid.parse(technology_id));  technology["productgroups"] = new bsonarray().add(bsonvalue.create(productgroup));  technologies.save(technology); 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -