1.0.3 • Published 7 years ago

firestore-port v1.0.3

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

firestore-port

NPM module to export and import Firebase's Firestore data.

Installation

Install using npm.

npm install firestore-port

Get Google Cloud Account Credentials from Firebase

You can Generate New Private Key from Project Settings from Firebase Console.

After that you need to copy the databaseURL for initiating the App.

Usage

You have to import this package in a JavaScript file and work from there.

Export data from firestore

You can export collection and sub collection from your data. The sub collection is optional.

// In your index.js 

const firestorePorter = require('firestore-port');
const serviceAccount = require('./serviceAccountKey.json');

// Initiate Firebase App
firestorePorter.initializeApp(serviceAccount, databaseURL);

// Start exporting your data
firestorePorter
  .export('collection-name', 'sub-collection-name-optional')
  .then(data => console.log(JSON.stringify(data)))

Get all collections data

Pass in an array of collection names to get data from the collections.

The result is an object of collection's data.

firestorePorter
  .exports(['collection1', 'collection2'])
  .then(collections => {
    // You can do whatever you want with collections
    console.log(JSON.stringify(collections));
  })

Import data to firestore

This code will help you to import data from a JSON file to firestore

// In your index.js 

const firestorePorter = require('firestore-port');
const serviceAccount = require('./serviceAccountKey.json');

// Initiate Firebase App
firestorePorter.initializeApp(serviceAccount, databaseURL);

// Start importing your data
// The array of date fields is optional
firestorePorter.import('your-file-path.json', ['field1', 'field2']);

Contributions

This project is inspired by suggestions from jcummings2 and leningsv. Feel free to report bugs and make feature requests in the Issue Tracker, fork and create pull requests!

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago