Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dracaster/lushan-packages
Set of packages to make development easier
https://github.com/dracaster/lushan-packages
batch csv export export-csvfile export-to-csv mongodb-database nodejs
Last synced: about 2 months ago
JSON representation
Set of packages to make development easier
- Host: GitHub
- URL: https://github.com/dracaster/lushan-packages
- Owner: DraCaster
- Created: 2020-04-06T17:10:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-25T21:47:17.000Z (over 3 years ago)
- Last Synced: 2024-10-29T14:21:43.395Z (about 2 months ago)
- Topics: batch, csv, export, export-csvfile, export-to-csv, mongodb-database, nodejs
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Contributors][contributors-shield]][contributors-url]
[![Stargazers][stars-shield]][stars-url]# 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
```js
npm install @dracaster/[email protected]
```
### Usage
```js
const csv = require(‘lushan-export-to-csv’);
```
### Methods:
```js
exportCsv()
```
### Definition and usage:
_Allows you to generate a csv batch. This method returns the download link of the generated file_
### Syntax
```js
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
```js
const csv = require(‘lushan-export-to-csv’);
const headers = ['name','telephone']
const baseUrl = "YOUR_API_URL"
/*This is an example of how you can get a cursor in MongoDB_
In this example I want to filter on my people collection, and get certain fields*///queryFilters: filters to apply
//headers: I return the fields that I require to generate my csv (These will be the headers in my batch file)let cursor = await people.find(queryFilters, headers).cursor()
csv.exportCsv('My-Company', headers, cursor, baseUrl, 'batches')
```
[stars-shield]: https://img.shields.io/github/stars/dracaster/lushan-export-to-csv.svg?style=flat-square
[stars-url]: https://github.com/DraCaster/lushan-export-to-csv/stargazers
[contributors-shield]: https://img.shields.io/github/contributors/dracaster/lushan-export-to-csv.svg?style=flat-square
[contributors-url]: https://github.com/dracaster/lushan-export-to-csv/graphs/contributors