diff --git a/mongodb-seeder/src/seeder.ts b/mongodb-seeder/src/seeder.ts index 36c3364c53cf60861626eaf2340c271bef73b24d..5eb7df9adbdcef442e8e2b3df68e948da1d1838f 100644 --- a/mongodb-seeder/src/seeder.ts +++ b/mongodb-seeder/src/seeder.ts @@ -18,6 +18,10 @@ export async function seedDatabase( // Get the collection instance const collection = db.collection(collectionName); + // Ensure collection is empty + const count = await collection.countDocuments(); + if (count !== 0) throw new Error('Collection already contains documents.'); + // Add timestamps to each data object const now = new Date(); const dataWithTimestamps = data.map((item) => ({