* Handles processing for a newly added file. * Creates the collection, inserts data, and updates the index collection.
(db: Db, filepath: string)
| 214 | * Creates the collection, inserts data, and updates the index collection. |
| 215 | */ |
| 216 | async function _handleFileAdded(db: Db, filepath: string): Promise<void> { |
| 217 | const collectionName = getCollectionNameFromJsonFile(filepath); |
| 218 | if (!collectionName) { |
| 219 | console.warn(`Could not determine collection name for added file ${filepath}. Skipping.`); |
| 220 | return; |
| 221 | } |
| 222 | console.log(`\nProcessing Added file ${filepath} for collection '${collectionName}'...`); |
| 223 | |
| 224 | const currentData = await readFileContent(filepath); |
| 225 | // For added files, oldData is empty |
| 226 | const { operations, skippedRecords } = calculateBulkOperations([], currentData, filepath); |
| 227 | await executeBulkWrite(db, collectionName, operations); |
| 228 | |
| 229 | if (skippedRecords > 0) { |
| 230 | console.warn(`Skipped ${skippedRecords} records in ${filepath} due to missing 'index' field.`); |
| 231 | } |
| 232 | |
| 233 | // Update index collection |
| 234 | await updateIndexCollection(db, filepath, 'upsert'); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Handles processing for a modified file. |
no test coverage detected