Skip to content
Snippets Groups Projects
Commit 5be5c0d0 authored by Felipe D'Abrantes's avatar Felipe D'Abrantes
Browse files

Ensure collection is empty

parent f1ad69fe
No related branches found
No related tags found
1 merge request!30Implement Mongo Seeder
......@@ -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) => ({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment