如何编写一个CLI函数,让用户提供JSON种子文件的文件路径,以便填充MongoDB数据库?
例如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);
字符串
1条答案
按热度按时间hfwmuf9z1#
使用mongoDB包的解决方案:
npm i mongodb
字符串
使用mongoose包的解决方案:
npm i mongoose
型