JSPM

firestore-bulk-loader

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q23496F
  • License MIT

A simple tool to load data to Cloud Firestore.

Package Exports

  • firestore-bulk-loader

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (firestore-bulk-loader) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

firestore-bulk-loader

Codacy Badge Build Status

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;

Contributors