How to write a CLI function that will let the user provide a file path to a JSON seed file in order to populate a MongoDB database?
e.g. node ./command.js seed ./seedfile.json
const program = require('commander');
program
.command('seed <filePath>')
.alias('s')
.description('Automatically add many entries from a json file')
.action(answer => seedEntries(answer)
);
const seedEntries = async (filePath) => {
//What to put here to get mongodb to accept the entries?
}
};
program.parse(process.argv);
Solution using mongoDB package:
npm i mongodb
Solution using the mongoose package:
npm i mongoose