( db: Db, collectionPrefix: string, collections: IndexEntry[] )
| 84 | } |
| 85 | |
| 86 | async function _refreshIndexCollection( |
| 87 | db: Db, |
| 88 | collectionPrefix: string, |
| 89 | collections: IndexEntry[] |
| 90 | ): Promise<void> { |
| 91 | console.log('\nRefreshing index table...'); |
| 92 | const collectionsCollectionName = getIndexCollectionName(collectionPrefix); |
| 93 | const collectionsCollection: Collection = db.collection(collectionsCollectionName); |
| 94 | |
| 95 | try { |
| 96 | await collectionsCollection.drop(); |
| 97 | console.log(` Dropped existing collection '${collectionsCollectionName}'.`); |
| 98 | } catch (err) { |
| 99 | if (!(err instanceof MongoServerError && err.codeName === 'NamespaceNotFound')) { |
| 100 | console.error(` Error dropping collection '${collectionsCollectionName}':`, err); |
| 101 | throw err; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | if (collections.length > 0) { |
| 106 | try { |
| 107 | const insertResult = await collectionsCollection.insertMany(collections); |
| 108 | console.log( |
| 109 | ` Inserted ${insertResult.insertedCount} documents into '${collectionsCollectionName}'.` |
| 110 | ); |
| 111 | } catch (err) { |
| 112 | console.error(` Error inserting documents into '${collectionsCollectionName}':`, err); |
| 113 | throw err; |
| 114 | } |
| 115 | } else { |
| 116 | console.log( |
| 117 | ` Skipping creation of collection '${collectionsCollectionName}' as no collections were processed.` |
| 118 | ); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | const uploadTablesFromFolder = async (db: Db, jsonDbDir: string, collectionPrefix = '') => { |
| 123 | const collectionIndexEntries: IndexEntry[] = []; |
no test coverage detected