Skip to content

Commit 52bfd4f

Browse files
committed
fetch collstats only if db exists
1 parent 32f9ae5 commit 52bfd4f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/collection-model/lib/model.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,22 @@ const CollectionModel = AmpersandModel.extend(debounceActions(['fetch']), {
239239
if (!shouldFetch(this.status, force)) {
240240
return;
241241
}
242+
// When trying to fetch collectionStats for a namespace whose db does not exist,
243+
// the server throws an error. This happens because we show dbs/collections to
244+
// the user from their roles/privileges. So, if the database does not exist, we
245+
// skip fetching collectionStats for the namespace.
246+
const dbExists = !getParentByType(this, 'Database').is_non_existant;
242247
try {
243248
const newStatus = this.status === 'initial' ? 'fetching' : 'refreshing';
244249
this.set({ status: newStatus });
245250
const [collStats, collectionInfo] = await Promise.all([
246-
dataService.collectionStats(this.database, this.name),
251+
dbExists ? dataService.collectionStats(this.database, this.name) : null,
247252
fetchInfo ? dataService.collectionInfo(this.database, this.name) : null,
248253
]);
249254
this.set({
250255
status: 'ready',
251256
statusError: null,
252-
...collStats,
257+
...(collStats && collStats),
253258
...(collectionInfo && pickCollectionInfo(collectionInfo)),
254259
});
255260
} catch (err) {

0 commit comments

Comments
 (0)