From a1a787ec81cc00f1641b26f45e1c63974202f751 Mon Sep 17 00:00:00 2001 From: "Kar@k5" Date: Tue, 24 Feb 2026 23:34:00 +0530 Subject: [PATCH] 1 --- src/app/api/import-json/route.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/app/api/import-json/route.ts b/src/app/api/import-json/route.ts index fb7ad3d..bab130b 100644 --- a/src/app/api/import-json/route.ts +++ b/src/app/api/import-json/route.ts @@ -148,19 +148,26 @@ export async function POST(request: NextRequest) { // Convert MongoDB extended JSON to proper MongoDB documents const documents = rawDocuments.map((doc: any) => convertMongoExtendedJSON(doc)); + // Get collection name from filename (without .json extension) + const collectionName = file.name.replace(/\.json$/i, ''); + // Get MongoDB collection const db = await getDatabase(); - const collection = db.collection('observations'); + const collection = db.collection(collectionName); + + // Drop existing collection if it exists + await collection.drop().catch(() => {}); // Insert documents const result = await collection.insertMany(documents); return NextResponse.json({ success: true, - message: `Successfully imported ${result.insertedCount} observations from ${file.name}`, + message: `Successfully imported ${result.insertedCount} documents into collection '${collectionName}' from ${file.name}`, inserted_count: result.insertedCount, inserted_ids: Object.values(result.insertedIds), filename: file.name, + collection_name: collectionName, size: `${(file.size / 1024).toFixed(2)} KB` });