Hey there good people!
I’ve noticed an issue with driver while trying to update a segment of my document in the database.
I have the following markup for my entities - A WorkDay Object that holds a datetime, 3 Shift Types - each holding a List
{ "_id": { "$oid": "5f376d7ca1787ac4d407c891" }, "Date": { "$date": "2020-07-11T21:00:00.000Z" }, "DayShift": { "Employees": [] }, "EveningShift": { "Employees": [] }, "NightShift": { "Employees": [] } }
I’m calling an API to make an update and pass the _id of the workday and a list of employee Ids that I want present at that particular shift on that day.
public async Task UpdateDayShift(string workDayId, List<string> empIds)
{
// get all employees
var employees = await _employees.AsQueryable<Employee>().ToListAsync();
// get current instance of the workday from the database
var newWorkDay = await _workDays.FindAsync<WorkDay>(d => d.Id == workDayId).Result.FirstAsync();
// clear content of dayshift
newWorkDay.DayShift.Employees.Clear();
// add only the selected employees into the shift
foreach (var e in employees)
{
if (empIds.Contains(e.Id))
{
newWorkDay.DayShift.Employees.Add(e);
}
}
// set filter and update params
var filter = Builders<WorkDay>.Filter.Eq("_id", newWorkDay.Id);
var update = Builders<WorkDay>.Update.Set(f => f.DayShift, newWorkDay.DayShift);
//update shift
await _workDays.FindOneAndUpdateAsync(filter, update);
}
I know for a fact the parameters I give are valid through debugging, and that there’s an established connection.
My API also returns a 200 code, but no updates actually occur on the database.
Has anyone encountered this issue?
Kind regards,