2011-06-08 95 views
3

鑑於此包裝:流利蒙戈COUNT()性能

public MongoCollection<TEntity> GetQuery<TEntity>() where TEntity : class 
    { 
     var query = DataBase.GetCollection<TEntity>(typeof(TEntity).Name + "s"); 
     return query; 
    } 

    public long Count<TEntity>(System.Linq.Expressions.Expression<Func<TEntity, bool>> criteria) where TEntity : class 
    { 
     return this.GetQuery<TEntity>().AsQueryable().Count(criteria); 
    } 

如果我調用COUNT(),將查詢服務器上執行的文檔here中規定?

var count = db<MyEntity>.Count(x => x.Foo = "foo"); 

回答

3

是的。它將在服務器端執行。您可以通過在MongoDB服務器上開始分析並查看執行的內容來驗證這一點。

+0

謝謝你的快速週轉! – rboarman 2011-06-08 01:03:04