-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImportingData.js
More file actions
31 lines (24 loc) · 821 Bytes
/
Copy pathImportingData.js
File metadata and controls
31 lines (24 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const xlsx = require('xlsx');
const connectDB = require('./config/db');
const mongoose = require('mongoose');
const Quran = require('./models/Quran');
const filePath = 'Quran.xlsx';
async function importData() {
// Read data from XLS file
const workbook = xlsx.readFile(filePath);
const sheetName = workbook.SheetNames[0];
const data = xlsx.utils.sheet_to_json(workbook.Sheets[sheetName]);
try {
// Initialize the database connection
connectDB();
// Insert data into MongoDB without MD5 hash
await Quran.insertMany(data);
console.log('Data imported successfully.');
// Close the MongoDB connection
mongoose.connection.close();
} catch (error) {
console.error('Error importing data:', error);
}
}
// Run the import function
importData();