showing results for - "export mongo to csv node"
Adam
23 Jun 2020
1const json2csv = require('json2csv').parse;
2
3//For unique file name
4const dateTime = new Date().toISOString().slice(-24).replace(/\D/g, 
5'').slice(0, 14); 
6
7const filePath = path.join(__dirname, "../../../", "public", "exports", "csv-" + dateTime + ".csv");
8
9let csv; 
10
11const student = await req.db.collection('Student').find({}).toArray();
12
13// Logging student
14// [{id:1,name:"John",country:"USA"},{id:1,name:"Ronny",country:"Germany"}]
15
16const fields = ['id','name','country'];
17
18 try {
19        csv = json2csv(booking_info, {fields});
20    } catch (err) {
21        return res.status(500).json({err});
22    }
23
24 fs.writeFile(filePath, csv, function (err) {
25        if (err) {
26            return res.json(err).status(500);
27        }
28        else {
29            setTimeout(function () {
30                fs.unlink(filePath, function (err) { // delete this file after 30 seconds
31                if (err) {
32                    console.error(err);
33                }
34                console.log('File has been Deleted');
35            });
36
37        }, 30000);
38            res.download(filePath);
39        }
40    })
41
queries leading to this page
nodejs mongodb to csvmongo import csv file example node jssave csv to mongodb with expresshow to save csv file using nodejs and mongodbexport mongodb collection to csv nodejshow to extract entire mongo collection in csv by node jsexport collection to csv mongodb node expressexport mogodb db csv nodejsmongodb json to csv nodejsimport csv file in mongodb mongoshimport csv to mongodb nodejshow to import csv file into my mongodb using nodejshow to convert mongodb data into csv using node jsstore csv to mongodb in nodenode js mongoimport csvnode import csv to mongodbhow to import csv file into mongodb using node jsexport mongodb to csv nodejsmongodb result to csv in nodejsimport csv file into mongodb using node jsimport csv file nodejs and mongodbgenerate csv from mongo response and save to file system nodejscsv file in express nodejs mongodbhow to import a csv with nodejs 26 mongomongodb export collection to csv nodejsstore csv to mongodb collection in nodecsv file to mongodb with nodejsexport mongo to csv nodehow to export mongodb collection as csv and download on user system in node jsnode script to export mongodb query to csv filehow to export mongodb data as a csv file in node jshow to save a csv file to mongo db with node jsimport csv nodejs and mongocsv file data add mongodb in node jsconvert mongodb data to csv in expresshow to upload csv file to mongo db using node export data from mongodb to csv node jsexport mongodb data to csv dev to in node jscsv to mongodb node jsmongodb to csv nodejsmongodb export collection to csv nodejs routegenerate csv from mongodb node jsexport entire mongoose collection to csv in nodecsv file to database import using node js mongodbexport db csv node mongodbexport mongodb collection to csv in nodejshow to export entire collection of mongodb in excel by nodecsv to mongodb nodejsgenerate csv mongodb nodeimport csv file to mongodb using node jsnode js export mongodb to csvnodejs import csv file on mongodbhow to export and download mongodb collection to csv in node jsnode js import csv to mongodbimport csv file in mongodbsave csv file to mongodb using node jsnodejs mongodb save csvcsv in node and mongostore csv to mongo via nodehow to import csv file in mongodb using node jsexport entire mongo collection to csv in nodehow to export mongodb database to csv in expresshow to upload csv file to mongodb using node jsexport collection to csv mongodb node express downloadexport mongo to csv node