public void AppendRecord <T>(string table, string id, LocationObject ld) { var collection = db.GetCollection <T>(table); var filter = Builders <T> .Filter.Eq("areaName", id); var update = Builders <T> .Update.Push("locationsList", ld); var result = collection.UpdateOne(filter, update); }
public void UpdateLocationCases(LocationObject lo, AreaInfo ai, CaseInfo ci) { var collection = db.GetCollection <AreaInfo>("Areas"); var filter = Builders <AreaInfo> .Filter.And(Builders <AreaInfo> .Filter.Where(c => c.areaName == ai.areaName), Builders <AreaInfo> .Filter.Where(c => c.locationsList.Any(x => x.locName == lo.locName))); var update = Builders <AreaInfo> .Update.PullFilter("locationsList.$[].casesList", Builders <BsonDocument> .Filter.Eq("caseID", ci.caseID)); collection.UpdateOne(filter, update); collection.FindOneAndUpdate(c => c.areaName == ai.areaName && c.locationsList.Any(s => s.locName == lo.locName), Builders <AreaInfo> .Update.Push(c => c.locationsList[-1].casesList, ci)); }
private void settingsLocAddButton_Click(object sender, EventArgs e) { string locName = ShowDialog("Enter Location Name", "New Add Location", true); string areaName = settingsAreaListView.SelectedItems[0].Text; if (locName.Length > 0) { LocationObject lo = new LocationObject(); lo.locName = locName; if (MongoCRUD.GetInstance().RecordExists <AreaInfo>("Areas", areaName, "areaName")) { MongoCRUD.GetInstance().AppendRecord <AreaInfo>("Areas", areaName, lo); RefreshLocationsList(settingsAreaListView.SelectedItems[0].Text); } } }