TurnerSoftware / MongoFramework

An "Entity Framework"-like interface for MongoDB
MIT License
392 stars 35 forks source link

Update not accepting changes #363

Closed grounzero closed 1 year ago

grounzero commented 1 year ago

I'm having an issue updating documents. I can see in the profiler it is calling UpdateOne with the new values but they're not being persisted to the database.

I've even tried removing and adding the item but it does not accept any changes and I am not sure what else I can try. Is there a way to get MongoFramework to use ReplaceOne instead or could it be something else?

context.Items.RemoveById(item.Id)
context.Items.Add(item.Id)

await context.SaveChangesAsync();
Turnerj commented 1 year ago

Can you post a minimal example of code that has this problem, your .NET version, your MongoDB driver version (if you specify one explicitly), your MongoDB version and your MongoFramework version?

If the code really is getting to the point of creating an UpdateOne model, that sounds like an obscure driver or database issue. Or maybe something else is special about your model you're trying to persist.

grounzero commented 1 year ago

I'm trying to get a minimal example but atm cannot get a repro. Is it possible to specify a MongoDB driver version using the nuget package?

dotnet 7.0.9 MongoFramework 0.29.0 MongoDB.Driver 2.19.2.0 Mongo 4.4

grounzero commented 1 year ago

I finally found the issue. It was updating a new object instance that had updated the _id prop with a new Guid so it was never able to find the existing instance to update!