firestore-bulk-loader
v1.1.0
Published
A simple tool to load data to Cloud Firestore.
Downloads
4
Maintainers
Readme
firestore-bulk-loader
A simple tool to load data to Cloud Firestore.
How to install
npm i firestore-bulk-loader
How to Use
Basic usage:
const bulkLoader = require('firestore-bulk-loader');
const serviceAccount = require('./path/to/service-account.json');
const data = require('path/to/data.json');
bulkLoader.load(data, "my-collection", serviceAccount);
or
const bulkLoader = require('firestore-bulk-loader');
const serviceAccount = require('./path/to/service-account.json');
const data = [
{ name:"John", age:30 },
{ name:"Mario", age:25 },
{ name:"Bruna", age:33 }
];
bulkLoader.load(data, "my-collection", serviceAccount);
To specify a custom id:
WARN: The document will be updated if an existing ID is used.
const bulkLoader = require('firestore-bulk-loader');
const serviceAccount = require('./path/to/service-account.json');
const data = [
{ myId: "j1", name:"John", age:30 },
{ myId: "m2", name:"Mario", age:25 },
{ myId: "b3", name:"Bruna", age:33 }
];
// the name of the attribute to use as ID.
var options = {
documentKeyProperty: "myId"
}
bulkLoader.load(data, "my-collection", serviceAccount, options);
CSV files:
const bulkLoader = require('firestore-bulk-loader');
const serviceAccount = require('./path/to/service-account.json');
const data = require('./path/to/data.csv');
var options = {
csv: true
}
bulkLoader.load(data, "my-collection", serviceAccount, options);
Options
| Parameter | Description | Default | Required | |---------------------|----------------------------------------|----------|----------| | documentKeyProperty | The name of the attribute to use as ID | | No | | csv | specifies that the data type is CSV | false | No |
Considerations
- If you load a collection that dons't exists in the Firestore it will be created;
- If the collections already exist in the Firestore all the data will be added to the existent collection;
- A Document will only be replaced if the given 'id' alread exists in the collection. This case only happens when used documentKeyProperty option;