Mongodb MonoDb Cshare Samus使用集合。计数<;T>;(func)或shell db.collection.find(condition).count()非常慢
很抱歉打扰您关于MongoDb for Cshare驱动程序(Samus)的问题,您能帮我看一下吗Mongodb MonoDb Cshare Samus使用集合。计数<;T>;(func)或shell db.collection.find(condition).count()非常慢,mongodb,count,Mongodb,Count,很抱歉打扰您关于MongoDb for Cshare驱动程序(Samus)的问题,您能帮我看一下吗 using (Mongo mongo = new Mongo(config.BuildConfiguration())) { mongo.Connect(); try { var db = mongo.GetDatabase("MyCollection");//Collecti
using (Mongo mongo = new Mongo(config.BuildConfiguration()))
{
mongo.Connect();
try
{
var db = mongo.GetDatabase("MyCollection");//Collection 's count > 500,000,000
var collection = db.GetCollection<BasicData>();
Console.WriteLine("Count by LINQ on typed collection: {0}", collection.Linq().Count(x => x.Id > 1));////error ,timeout
Console.WriteLine("Count by not LINQ on typed collection: {0}", collection.Count()); //no condition is ok
Console.ReadKey();
}
finally{
mongo.Disconnect();
} }
使用(Mongo Mongo=new Mongo(config.BuildConfiguration())
{
mongo.Connect();
尝试
{
var db=mongo.GetDatabase(“MyCollection”);//集合的计数>500000000
var collection=db.GetCollection();
WriteLine(“在类型化集合上按LINQ计数:{0}”,collection.LINQ().Count(x=>x.Id>1));///错误,超时
Console.WriteLine(“在类型化集合上按not LINQ计数:{0}”,collection.Count());//没有条件是确定的
Console.ReadKey();
}
最后{
mongo.Disconnect();
} }
使用Mongodb shell:
db.collection.find(条件).count()
或
db.collection.count(条件)//非常慢如果它在shell中也很慢,那么它与C#driver没有任何关系 用于确定查询是否使用预期的索引。如果不使用索引,任何超过5亿个文档的查询都需要一些时间。在外壳中:
db.collection.find(condition).explain();
为了加快查询速度,您可能需要添加一个包含查询条件的字段。谢谢,我已经为查询创建了数据索引。我的服务器内存为64G,但查询速度仍然很慢(只有计数查询速度慢,其他函数查询正常),您能否帮助找到其他方法来解决此问题?您的文档是什么样子的?你创建了什么索引?
条件
包含什么?您是否等待索引创建完成?