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.

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
Post a Comment