How do I use the AsQueryable method asynchronously with MongoDb C# Driver 2.1?

You’re returning the wrong type from the GetFiltered function. It should be returning an IMongoQueryable<MyType> instead of IQueryable<MyType>:

public IMongoQueryable<MyType> GetFiltered(Expression<Func<MyType, bool>> predicate)
{
    return Database.GetCollection<MyType>(typeof(MyType).Name).AsQueryable()
        .Where(predicate);
}

You can then successfully call it as:

var myTypes = await MyRepository.GetFiltered(t => t.Id == 1).ToListAsync();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)