项目作者: DraCaster

项目描述 :
Export records stored in the Mongo DB, to a CSV file.
高级语言: JavaScript
项目地址: git://github.com/DraCaster/lushan-export-to-csv.git
创建时间: 2020-04-06T17:10:11Z
项目社区:https://github.com/DraCaster/lushan-export-to-csv

开源协议:

下载


Contributors
Stargazers

lushan-packages

Set of packages to make development easier :)

Content:

  • lushan-export-to-csv
  • lushan-random-string

lushan-export-to-csv

You can export records stored in the Mongo DB, to a CSV file.

Installation

  1. npm install @dracaster/lushan-export-to-csv@1.0.0

Usage

  1. const csv = require(‘lushan-export-to-csv’);

Methods:

  1. exportCsv()

Definition and usage:

Allows you to generate a csv batch. This method returns the download link of the generated file

Syntax

  1. csv.exportCsv(EntityName, Headers, Cursor, BaseUrl, DestinationFolder)

Parameters values

  • EntityName : Required. Name of the entity you want to export. This will be used to generate the file name. For example citizens, companies, etc. (Type: String)

  • Headers : Required. Will be used as a column heading. (Type: Array)

  • Cursor : Required. A pointer to the result set of a query. Will be used to generate the batch. More information about cursors in MongoDB: https://docs.mongodb.com/manual/reference/glossary/#term-cursor

  • BaseUrl : Required. API base Url (Type: String)

  • DestinationFolder : Required. Destination folder where the csv is generated. This folder must exist in your project. (Type: String)

Example

  1. const csv = require(‘lushan-export-to-csv’);
  2. const headers = ['name','telephone']
  3. const baseUrl = "YOUR_API_URL"
  4. /*This is an example of how you can get a cursor in MongoDB_
  5. In this example I want to filter on my people collection, and get certain fields*/
  6. //queryFilters: filters to apply
  7. //headers: I return the fields that I require to generate my csv (These will be the headers in my batch file)
  8. let cursor = await people.find(queryFilters, headers).cursor()
  9. csv.exportCsv('My-Company', headers, cursor, baseUrl, 'batches')