Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MongoDb C#ToList()性能低下。有什么改进的方法吗?_C#_Mongodb_Performance_Driver_Tolist - Fatal编程技术网

MongoDb C#ToList()性能低下。有什么改进的方法吗?

MongoDb C#ToList()性能低下。有什么改进的方法吗?,c#,mongodb,performance,driver,tolist,C#,Mongodb,Performance,Driver,Tolist,正如标题所说,我发现MongoDb C#驱动程序在数据显示方面非常慢 我收集了1000份文件。它们不会增长,我需要从这个收藏中读很多东西。 一个简单的查询 db.GetCollection<BsonDocument>("collection_name") .Aggregate() .Match(Builders<BsonDocument>.Filter.Gte("age", 30)) db.GetCollection(“集


正如标题所说,我发现MongoDb C#驱动程序在数据显示方面非常慢

我收集了1000份文件。它们不会增长,我需要从这个收藏中读很多东西。
一个简单的查询

db.GetCollection<BsonDocument>("collection_name")
  .Aggregate()
  .Match(Builders<BsonDocument>.Filter.Gte("age", 30))
db.GetCollection(“集合名称”)
.Aggregate()
.Match(Builders.Filter.Gte(“年龄”,30))
可以找到大约200个文档,使用MongoDbCompass的解释计划,速度非常快

问题是当我需要显示这200个文档时(使用.ToList()或.ToListAsync()),需要10秒
对于800个文档,需要30秒
好吧,也许我不需要所有这些,因为我将向用户展示一个分页的网页=> 因此,我添加了一个跳过(n)和限制(n+20),但也有这个限制,它需要1.5秒才能显化。太多了

每个文档重1kb,它们都有20个属性,其中一个是子文档数组。目前,我得到的数据是BsonDocumet,因为我还没有决定文档结构

所以我在问。。。就这样结束了吗?我能做点什么吗

多谢各位!图特

编辑
我正在使用最新的C#MongoDb驱动程序(2.11.1)

Edit2
我为需要搜索的属性准备了索引。

此外,此结果来自localhost:27017,所以全部在本地。

为什么要调用
.Aggregate().Match(…)
而不仅仅是
.Find()
?谢谢您的评论。我也做其他的操作,这只是简单的一个。我制作了一个动态聚合管道,它可以做很多事情。你是说如果我在Find中使用builder.Filter比ToList更快吗?我不能肯定这会有什么不同,但我相信它们做的事情略有不同。我尝试了FindSync()和FindAsync(),但显示数据的性能结果与Aggregate()相同。Match(…)在这种情况下,我假设您没有关于“年龄”的索引。为什么要调用
.Aggregate().Match(…)
而不仅仅是
.Find()
?谢谢您的评论。我也做其他的操作,这只是简单的一个。我制作了一个动态聚合管道,它可以做很多事情。你是说如果我在Find中使用builder.Filter比ToList更快吗?我不能肯定这会有什么不同,但我相信它们做的事情略有不同。我尝试了FindSync()和FindAsync(),但显示数据的性能结果与Aggregate()相同。Match(…)在这种情况下,我假设你没有关于“年龄”的索引。