var querydetail = new Bsondocument ("CNo", DOC.CNO);
Querydetail.addrange (New Bsondocument ("Details.ddate", doc.ordate));
//Data with the same report date in the Daily table array
bool exist = Tbldays.findsync (Querydetail). Any ();
if (exist)
{
#region data for the same report date in the daily table array, the
is updated by field.
list<writemodel<bsondocument>> requests = new list<writemodel<bsondocument>> ();
Requests. ADD (New updateonemodel<bsondocument> (_query, update) {Isupsert = true});
var updatedetail = new Bsondocument ();
foreach (Var propert in properties)
{
var vals = Propert. GetValue (detail);
if (Propert. PropertyType.BaseType.Name.Equals ("Enum"))
{
Vals = Convert.toint64 (Vals);
}
var tmpupdate = new Bsondocument () {{"$set", new Bsondocument () {string. Format ("details.$.{ 0} ", Propert. Name), Bsondocumentwrapper.create (Vals)}}};
Requests. ADD (New updateonemodel<bsondocument> (Querydetail, tmpupdate) {Isupsert = true});
}
if (requests. Count > 0)
{
Tbldays.bulkwrite (requests);
}
#endregion
}
else {
#region data for the same report date does not exist in the day table array, it is added directly to the array
var updateset = new Bsondocument () {{"$addToSet", new Bsondocument () {{"Details", bsondocumentwrapper.create (detail)} } } };
Update. AddRange (Updateset);
Tbldays.updateone (_query, update, new UpdateOptions {Isupsert = true});
#endregion
}
C # MONGO object update in array