NPM module to export and import Firebase's Firestore data.
Install using npm.
npm install firestore-port
You can Generate New Private Key from Project Settings from Firebase Console.
After that you need to copy the databaseURL for initiating the App.
You have to import this package in a JavaScript file and work from there.
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)))
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));
})
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']);
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!