Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var firebase = require('firebase');
- var Converter = require("csvtojson").Converter;
- firebase.initializeApp({
- serviceAccount: "./credentials.json",
- databaseURL: "url went here"
- });
- var converter = new Converter({
- constructResult:false,
- workerNum:4
- });
- var db = firebase.database();
- var ref = db.ref("/");
- var lastindex = 0;
- var count = 0;
- var section = 0;
- var sectionRef;
- converter.on("record_parsed",function(resultRow,rawRow,rowIndex){
- if (rowIndex >= 0) {
- sectionRef = ref.child("reports" + section);
- var reportRef = sectionRef.child(resultRow.Report_ID);
- reportRef.set(resultRow);
- console.log("Report uploaded, count at " + count + ", section at " + section);
- count += 1;
- lastindex = rowIndex;
- if (count >= 1000) {
- count = 0;
- section += 1;
- }
- if (section >= 100) {
- console.log("last completed index: " + lastindex);
- process.exit();
- }
- } else {
- console.log("we out of indices");
- process.exit();
- }
- });
- var readStream=require("fs").createReadStream("./vUPLOAD_MASTER.csv");
- readStream.pipe(converter);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement