diff --git a/import-indexes.sh b/import-indexes.sh index c4b8f04..39150a9 100755 --- a/import-indexes.sh +++ b/import-indexes.sh @@ -57,8 +57,10 @@ for (const [collName, indexes] of Object.entries(data)) { } } - const existingIndexes = targetDb.getCollection(collName).getIndexes() - .filter(idx => idx.name !== "_id_"); + const collectionExists = existingCollections.has(collName); + const existingIndexes = collectionExists + ? targetDb.getCollection(collName).getIndexes().filter(idx => idx.name !== "_id_") + : []; if (existingIndexes.length > 0) { if (dryRun) {