Hi Community Members
Could use some advice/help on performance on MongoDB.
I have a query that takes approx. 30-40 seconds. It uses index on the collection for one of the fields (OriginForm.MemberType), but as it is also selecting on a field in an array of objects, this seems to take quite some time, as there is no index on this.
I can add the result from the profiler, if desired.
And the .net core code that calls is this:
return await _individualRepository.GetMongoCollection().FindSync(x => x.CurrentStatus > 0 && x.InfoList != null && x.Email != null && x.OriginForm != null && x.OriginForm.MemberType == MemberType && x.InfoList.Any(y => y.SId == “Location” && y.Value == user.LocationId)).ToListAsync();
The collection “Individuals” consists of regular fields, as well as an Object OriginForm (where the MemberType is located) and an array InfoList, which contains 50 objects, each with 5 or 6 fields.
What I want to be able to create an index for, ideally, is the OriginForm.Membertype and the InfoList.9.Value.
I am uncertain if creating a Multikey index will solve this - and if it will not generate a huge index, with the many objects and fields in the array? And/or if it is possible to create an index that both covers the Array field (InfoList.9.Value) as well as the Object field (OriginForm.Membertype), or if that needs to be two seperate indexes.
Any suggestions on how to solve this the best possible way?