I know how to import a CSV file as a collection using mongoimport in shell/cmd prompt, or using GUI such as 3T studio. each line is a document with headerline as their title.
For example a csv file name Data.csv headerline and content are as follow:
It can be done very easily using the above method if it is for just one file.
May I know is there a way to import multiple files (few hundred) where it can. -Separate each file as one collection -Use file name as collection name -Import all contents as each documents under the collections
Best is can use nodejs, but other method are more than welcome.
Thank you.
update
for i in `ls ~/te/*.csv`; do
./mongoimport -d test $i --type=csv --headerline ;
done
const exec = require('child_process').exec;
var yourscript = exec('bash mongoin.sh /te',
(error, stdout, stderr) => {
console.log(`${stdout}`);
console.log(`${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});