Home:ALL Converter>Performancing regex search on MongoDb collection

Performancing regex search on MongoDb collection

Ask Time:2019-03-19T05:14:52         Author:makeItEasier

Json Formatter

I have a collection with 546.8m documents. and I need to search some documents that matches the Username property.

I create this piece of foce

 FilterDefinition<ProfileEntity> f = Builders<ProfileEntity>.Filter.Regex("Username", new BsonRegularExpression(profileName,"i"));

                var profilesList = await collection.Find(f).Limit(25).ToListAsync();

But this is taking soo long time.

What can I do for a better performance?

Creating a index would increase the performance ina big scale?

The limit of records is fixed 25.

Using the client comand line or MongoDB Compass the search is soo fast .

When using with c# is soo slow.

Of course the between them has to be different . But I can't believe that is too much

Any ideas?

Author:makeItEasier,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/55230149/performancing-regex-search-on-mongodb-collection
yy