Consider the following code
var q = from e in myCollection.AsQueryable() where e.Name == \"test\" select e;
The actual query
A quick extension based on Robert Stam's answer:
public static IMongoQuery ToMongoQuery(this IQueryable linqQuery)
{
var mongoQuery = ((MongoQueryable)linqQuery).GetMongoQuery();
return mongoQuery;
}
public static WriteConcernResult Delete(this MongoCollection col, IQueryable linqQuery)
{
return col.Remove(linqQuery.ToMongoQuery());
}
public static WriteConcernResult Delete(this MongoCollection col, Expression> predicate)
{
return col.Remove(col.AsQueryable().Where(predicate).ToMongoQuery());
}
example:
myCollection.Remove(myCollection.AsQueryable().Where(x => x.Id == id).ToMongoQuery());
myCollection.Delete(myCollection.AsQueryable().Where(x => x.Id == id));
myCollection.Delete(x => x.Id == id);