Skip to content

Commit 3df07fa

Browse files
committed
another fix in option counts
1 parent 1a35804 commit 3df07fa

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

  • src/mddb-database/utils/count-options

‎src/mddb-database/utils/count-options/index.js‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ const countOptions = async (database, query, fields, shouldCountMds, useSavedCou
4343
// Request the saved counts matching the query
4444
const savedCounter = await database.counters.findOne({ query: query },
4545
{ projection: { _id: false, ...fieldProjections } });
46+
4647
// Now store the saved counts in the final options response
47-
Object.entries(savedCounter.fields).forEach(([ field, optionCounts ]) => {
48-
const renamedField = field.replaceAll('/', '.');
49-
if (!shouldCountMds) Object.entries(optionCounts).forEach(([value, counts]) => {
50-
optionCounts[value] = counts[0];
48+
if (savedCounter && savedCounter.fields)
49+
Object.entries(savedCounter.fields).forEach(([ field, optionCounts ]) => {
50+
const renamedField = field.replaceAll('/', '.');
51+
if (!shouldCountMds) Object.entries(optionCounts).forEach(([value, counts]) => {
52+
optionCounts[value] = counts[0];
53+
});
54+
options[renamedField] = optionCounts;
5155
});
52-
options[renamedField] = optionCounts;
53-
});
5456
}
5557
// Now get the rest of fields which were not already among the saved ones
5658
const missingFields = new Set([ ...fields ].filter(field => !(field in options)));

0 commit comments

Comments
 (0)