2015-06-21 13 views
0

MongoDB中C#2.0驅動程序MongoDB的C#2.0的驅動程序,如何尋找並找到或如何所在的位置以及和所有計數()

··· var lists = base.Collection.Aggregate(); 

     if (cId > 0) 
     { 
      lists = lists.Match(n => n.cId == cId); 
     } 
     if (!string.IsNullOrEmpty(spell)) 
     { 
      lists = lists.Match(n => n.Spell == spell || n.Name == spell); 
     } 
     // var count = lists.count(); 
     var results = lists.ToListAsync().GetAwaiter().GetResult() 

...

是的,這是工作,

但我想知道名單MongoDB中1.x的驅動程序的所有count(),以Skip()Limit()

var lists = base.collection.AsQueryable().where(n => n.cId == cId).where(n => n.Spell == spell || n.Name == spell)); 

var count = lists.count(); 
var result = lists.skip(10).limit(20).tolist(); 

我的問題:

如果比賽是正確的。如何馬成順得到所有結果count(),如果用火柴是不完美的方式,如何寫這個代碼

回答

0

這是你在找什麼?

得到收集

IMongoCollection<T>.CountAsync(new BsonDocument()).Result 

所有計數指定的計數

var filter = Builders<Trailer>.Filter.Eq("YourFieldName", "match value"); 
IMongoCollection<T>.CountAsync(filter).Result; 

聲明讓所有收集和使用跳過和限制

IMongoCollection<T>.Find(new BsonDocument()).Skip(skip).Limit(limit) 
       .ToListAsync().Result; 
相關問題