updateOne () method taking delay in updating document in database

I am using updateOne() method to update a document in database. Then just after updating I am logging results to see updated changes in document, changes are not reflecting. But when I am logging results after a sleep for 100 ms, changes are reflected. I am not able to understand why this delay is there.

Share your code. Most likely there is something wrong with it.

private void updateState(List FilesInfo, string state)
{
foreach(File file in FilesInfo)
{
file.State = state;
file.UpdateTime = DateTimeService.GetDateTime();

dbrepository.UpdateOne(i=>i.Id.Equals(file.Id), Builders.Update.Set(i=>i.State, state);
}
}

This function written in c# is used to update state of the file in database.

This is the code that does the update. It is the code doing the verification that’s important.

You should be doing your updateOne inside a bulkWrite to minimize database interaction.

I do not know c#, but is it possible that UpdateOne is asynchronous like in JS and that you need to await the result. Your sleep simply allows the async operation to complete.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.