MongoDb C# ToList() slow performance. Any way to improve?

Viewed 674


as the title says I found MongoDb C# Driver being very slow in term of data manifestation.

I have a collection with 1000 documents. They will not grow and I need to read a lot from this collection.
A simple query as

db.GetCollection<BsonDocument>("collection_name")
  .Aggregate()
  .Match(Builders<BsonDocument>.Filter.Gte("age", 30))

can found like 200 documents and with the explain plan of MongoDbCompass it is very fast.

The problem is when I need to manifest those 200 documents (with .ToList() or .ToListAsync()) it takes like 10 seconds.
For 800 documents it takes 30 seconds!
Ok maybe I don't need all of those because what I will show to the users is a paginated web page => so I added a Skip(n) and Limit(n + 20) but also with this limitation it takes 1.5 seconds to manifest. It is a lot!

Each document weight 1kb, they all have 20 properties which one is an array of subdocuments. For now I am getting the data as BsonDocumet because I haven't yet decided the document structure.

So I am asking... is this the end of it? There is something I can do about it?

Thank you very much! T_T

Edit
I am using the latest C# MongoDb Driver (2.11.1)

Edit2
I have indexes in place for the properties I need to search for.
Also this result are from localhost:27017, so all in local.

0 Answers
Related