I am using the latest MongoDB C# Driver and I am having a problem with one of my queries. I am trying to update a field in a document in Mongo and identify this document by it's id field. I have written similar queries that filter the documents based on other field but for some wreason it doesn't work with the id field.
My Query:
public static async Task<bool> Delete(string Guid)
{
var database = new MongoDB();
var thingsCollection = database.Things;
var builder = Builders<ThingsModel>.Filter;
var filter = builder.Eq("_id", Guid);
var update = Builders<ThingsModel>.Update
.Set("IsActive", false);
var updateResult = await thingsCollection.UpdateOneAsync(filter, update);
return true;
}
I realise I am returning true each time but that is just there for testing. The updateResult object that comes back from Mongo says it didn't find any matches despite the being a thing in the thingsCollection with the Guid passed in the as a parameter. I have also marked the Guid property to be the ID Field in the collection as follows:
[BsonId]
public Guid Guid { get; set; }
Also I know I need to change the name from Guid to something else as it bad practice but one thing at a time :) I appreciate any help!