0

I have a folder of .TXT extensions file with plain text in it how can I insert that plain text into the MongoDB database using the mongoose and fs module in node js

const fs = require('fs');
var parsedata;
var parsedTwice = [];
let fileName;
fs.readdir("D:/scnner_data/public", (err, data) => {
    if(err) throw err
    console.log(data);
    fileName = data;
    console.log(fileName);
});

fs.readFile('D:/scnner_data/public/DC221020042103SC.TXT',"utf8", (err,  data) =>{
    if (err) {
        console.log(err);
    } else {
         parsedata = data.split("\n");
         for(let item of parsedata) {
            parsedTwice.push(item.split(";"));
         }
        //console.log('successful' , parsedTwice);
        // console.log('this line is being readed' + parsedata);
    }
}
)
  • What do you want your document(s) to look like? I.e., what is your database data model? – rickhg12hs Nov 09 '22 at 05:51
  • we have data there is 6 TH and there are thousands of TD so we require the file using the FS module and we could convert it into JSON? – akasha sharma Nov 09 '22 at 10:39
  • Would you show what an example document looks like? Do you have a mongoose schema? What are some example queries you expect to make after you insert all your data? – rickhg12hs Nov 09 '22 at 12:57

0 Answers0