Skip to content

marcosvidolin/firestore-bulk-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •