MCPcopy Create free account
hub / github.com/5e-bits/5e-database / _refreshIndexCollection

Function _refreshIndexCollection

scripts/dbRefresh.ts:86–120  ·  view source on GitHub ↗
(
  db: Db,
  collectionPrefix: string,
  collections: IndexEntry[]
)

Source from the content-addressed store, hash-verified

84}
85
86async 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
122const uploadTablesFromFolder = async (db: Db, jsonDbDir: string, collectionPrefix = '') => {
123 const collectionIndexEntries: IndexEntry[] = [];

Callers 1

uploadTablesFromFolderFunction · 0.85

Calls 1

getIndexCollectionNameFunction · 0.90

Tested by

no test coverage detected