Mongo C# driver 2.0 - Find count without fetching documents

后端 未结 1 787
渐次进展
渐次进展 2021-01-06 08:07

A general count query will be doing a

int count = collection.Find(filter).Count();

Now that loads all the records as per the filter, so le

相关标签:
1条回答
  • 2021-01-06 08:20

    You need to use the explicit CountAsync method and not Find:

    long result = await collection.CountAsync(Builders<Hamster>.Filter.Eq(_ => _.Name, "bar"));
    
    0 讨论(0)
提交回复
热议问题