I am trying to create a deleteAll method in mongo where I could delete multiple records in one go bu supplying the method a list of object ids to be deleted something like this
protected virtual DeleteResult DeleteAll(List<ObjectId> listId, WriteConcern concern = null)
{
return MongoCollection
.DeleteManyAsync(ItemWithListOfId(listId))
.Result;
}
protected FilterDefinition<T> ItemWithListOfId(List<ObjectId> id)
{
return Builders<T>.Filter.Eq("_id", id);
}
it is giving no error but is not deleting any record as well. Anyone any help?
Instead of the Eq
filter, you need an In
filter method to match the id
values in a list, which is an implementation of the mongodb $in
query
protected FilterDefinition<T> ItemWithListOfId(List<ObjectId> id)
{
return Builders<T>.Filter.In("_id", id);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With