Thanks Eric,
I have a collection with a number of fields, and four of them are
location, skill, sector and activitytype
location for example as say, 10 possible values from 1000 documents.
I.e. any of those 1000 documents will only have one of 10 values.
skill might have 5 unique values , and so on.
I have a web search form where I populate a drop down for each of; location, sector, skill, activityrtype with the value and how many times that value occurs in the result set.
But I have to make 4 seperate queries like this in the c# class which gets the data for the view model.
TheModel.LocationCounts
= MongoClient.
GetSortByCount(UserCriteria, x => x.Location, User);
TheModel.ActivityCounts
= MongoClient.
GetSortByCount(UserCriteria, x => x.Activity, User);
TheModel.SectorCounts
= MongoClient.
GetSortByCount(UserCriteria, x => x.Sector, User);
TheModel.SkillCounts
= MongoClient.
GetSortByCount(UserCriteria, x => x.Skill, User);
Each of the above is doing the following
Results =
Collection.
Aggregate().
Match(Filter).
SortByCount(Field).
SortBy(x => x.Id).
ToList();
Can I do the above for 4 fields and get for lists of unique values and their occurrence type?
e.g. get the date for four dropdowns like the following at once.
For those reading this (I expect Eric knows this) and looking at the seemingly hard coded
SortBy(…) SortByCount() returns the same class always and Id is the unique value in the list. so x.Id is always present.
Thanks