I encountered an issue with my functions for importing data from a JSON file into the database. When I tried calling the importData function alone, it didn't work. However, when I called deleteData first and then importData, the database ended up empty.
const tours = JSON.parse(
fs.readFileSync(`${__dirname}/tours-simple.json`, 'utf-8')
);
const deleteData = async () => {
try {
await Tour.deleteMany();
} catch (error) {
console.log(error);
}
};
//Importing data into the database
const importData = async () => {
try {
await Tour.create(tours);
console.log('Successfully loaded data!');
} catch (error) {
console.log(error);
}
};
deleteData();
importData();