Skip to content

Commit fb98c6e

Browse files
authored
Merge pull request #49 from flutter-news-app-full-source-code/add-indexes-for-country-aggregation-queries
feat(database): add indexes for country aggregation queries
2 parents acb499b + 735018f commit fb98c6e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/src/services/database_seeding_service.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ class DatabaseSeedingService {
118118
.collection('sources')
119119
.createIndex(keys: {'name': 'text'}, name: 'sources_text_index');
120120

121+
// Indexes for country aggregation queries
122+
await _db
123+
.collection('headlines')
124+
.createIndex(
125+
keys: {'status': 1, 'eventCountry.id': 1},
126+
name: 'status_eventCountry_index',
127+
);
128+
await _db
129+
.collection('sources')
130+
.createIndex(
131+
keys: {'status': 1, 'headquarters.id': 1},
132+
name: 'status_headquarters_index',
133+
);
134+
121135
// --- TTL and Unique Indexes via runCommand ---
122136
// The following indexes are created using the generic `runCommand` because
123137
// they require specific options not exposed by the simpler `createIndex`

0 commit comments

Comments
 (0)