All Projects → jloosli → Node Firestore Import Export

jloosli / Node Firestore Import Export

Licence: mit
Firestore data import and export

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Node Firestore Import Export

Firestore Backup Restore
NPM package for backup and restore Firebase Firestore
Stars: ✭ 307 (+13.28%)
Mutual labels:  firebase, backup, firestore, restore
Node Firestore Backup
Google Firebase Firestore backup tool
Stars: ✭ 192 (-29.15%)
Mutual labels:  firebase, backup, firestore
Dynein
DynamoDB CLI written in Rust.
Stars: ✭ 126 (-53.51%)
Mutual labels:  export, import, backup
open2fa
Two-factor authentication app with import/export for iOS and macOS. All codes encrypted with AES 256. FaceID & TouchID support included. Written with love in SwiftUI ❤️
Stars: ✭ 24 (-91.14%)
Mutual labels:  export, backup, import
Elasticsearch Dump
Import and export tools for elasticsearch
Stars: ✭ 5,977 (+2105.54%)
Mutual labels:  export, import, backup
connect-backup
A tool to backup and restore AWS Connect, with some useful other utilities too
Stars: ✭ 19 (-92.99%)
Mutual labels:  export, backup, import
Pring
Cloud Firestore model framework for iOS - Google
Stars: ✭ 260 (-4.06%)
Mutual labels:  firebase, firestore
fb-export
Export (most) of your Facebook data using Node.js and the Graph API.
Stars: ✭ 21 (-92.25%)
Mutual labels:  export, backup
Burry.sh
Cloud Native Infrastructure BackUp & RecoveRY
Stars: ✭ 260 (-4.06%)
Mutual labels:  backup, restore
restique
A wrapper around restic with profiles
Stars: ✭ 43 (-84.13%)
Mutual labels:  backup, restore
browserexport
backup and parse browser history databases (chrome, firefox, safari, and other chrome/firefox derivatives)
Stars: ✭ 54 (-80.07%)
Mutual labels:  export, backup
l2cu
L²CU: LDraw Linux Command line Utility
Stars: ✭ 14 (-94.83%)
Mutual labels:  export, import
React Admin Firebase
A firebase data provider for the react-admin framework
Stars: ✭ 269 (-0.74%)
Mutual labels:  firebase, firestore
qgis-kmltools-plugin
Fast KML Import and Export Plugin for QGIS
Stars: ✭ 45 (-83.39%)
Mutual labels:  export, import
excel mysql
Module for import Excel files to MySQL table and export MySQL table to Excel file using PHPExcel
Stars: ✭ 30 (-88.93%)
Mutual labels:  export, import
VBA-Import-Export
Export & Import VBA code for use with Git (or any VCS)
Stars: ✭ 14 (-94.83%)
Mutual labels:  export, import
arctee
Atomic tee
Stars: ✭ 22 (-91.88%)
Mutual labels:  export, backup
zabbix-review-export-import
Clone of zabbix-review-export with added import object(s) feature
Stars: ✭ 36 (-86.72%)
Mutual labels:  export, import
Shrimpit
Shrimpit 🍤 is a small CLI analysis tool for checking unused JavaScript, JSX & Vue templates ES6 exports in your project.
Stars: ✭ 255 (-5.9%)
Mutual labels:  export, import
filmow to letterboxd
🎥 💚To import Filmow watched movies in Letterboxd. The script can be found on the letterboxd page about importing data under "Additional tools".
Stars: ✭ 13 (-95.2%)
Mutual labels:  export, import

node-firestore-import-export

Firestore data importing, exporting, and data clearing tool.

codebeat badge Codacy Badge David badge Known Vulnerabilities CircleCI

Export a Firestore database, including collections and documents, while keeping the structure intact.

Table of Contents

Data Format

Exports a json file with the following format:

{
  "__collections__": {
    "companies": {
      "docA": {
        "name": "Big Co",
        "employee_count": 2012,
        "created": {
          "__datatype__": "timestamp",
          "value": {
            "_seconds": 12343456,
            "_nanoseconds": 7890
          }
        },
        "location": {
          "__datatype__": "geopoint",
          "value": {
            "_latitude": -123.456789,
            "_longitude": 34.5678
          }
        },
        "AdministratorRef": {
          "__datatype__": "documentReference",
          "value": "path/to/the/document"
        },
        "__collections__": {
          "employees": ...,
          "products": ...
        }
      },
      "docB": ...,
      "docC": ...
    },
    "administrators": {
      "docA": ...,
      "docB": ...
    }
  }
}

where __collections__ holds the collections for a given document (or the root of the database).

Imports need to be from a file with the same structure (e.g. from an exported file).

Be careful! This can easily overwrite or mess up your data if you import to the wrong location.

Special Datatypes

Three types of data are serialized in the export:

  • Timestamps
  • Geopoints
  • DocumentReferences

They each are serialized in the following format:

{
  "__datatype__": "timestamp|geopoint|documentReference",
  "value": "The serialized value"
}

Installation

Install using npm.

npm install -g node-firestore-import-export

or yarn

yarn global add node-firestore-import-export

Alternatively download the source.

git clone https://github.com/jloosli/node-firestore-import-export.git

Retrieving Google Cloud Account Credentials

  1. Visit the Firebase Console
  2. Select your project
  3. Navigate to Project Settings (at the time of writing the gear icon button at the top left of the page).
  4. Navigate to Service Accounts
  5. Click Generate New Private Key

This downloaded json file contains the proper credentials needed for node-firestore-import-export to authenticate.

Using Firebase Firestore Emulator

If using Firebase Emulators, all commands (Export, Import, and Clear) will override the account credentials setting if the FIRESTORE_EMULATOR_HOST environment variable is set.

Usage

Command Line

The path to the account credentials can either be passed with the -a/--accountCredentials flag, or placed in the GOOGLE_APPLICATION_CREDENTIALS environment variable. For example:

export GOOGLE_APPLICATION_CREDENTIALS=path/to/my/credentials.json
firestore-export -p

Export

  • -a, --accountCredentials <path> - path to Google Cloud account credentials JSON file. If missing, will look at the GOOGLE_APPLICATION_CREDENTIALS environment variable for the path.
  • -b, --backupFile <path>- Filename to store backup. (e.g. backups/full-backup.json). Defaults to firestore-export.json if missing.
  • -n, --nodePath <path>- Path to database node to start (e.g. collectionA/docB/collectionC). Backs up full database if empty or missing.
  • -p, --prettyPrint - JSON backups done with pretty-printing.
Examples
Export full database
firestore-export --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json
Export with pretty printing
firestore-export --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json --prettyPrint
Export from a specific path (and all its children/collections)
firestore-export --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json --nodePath collectionA/document1/collectionCC

Import

  • -a, --accountCredentials <path> - path to Google Cloud account credentials JSON file. If missing, will look at the GOOGLE_APPLICATION_CREDENTIALS environment variable for the path.
  • -b, --backupFile <path>- Filename with backup data. (e.g. backups/full-backup.json).
  • -n, --nodePath <path>- Path to database node to start (e.g. collectionA/docB/collectionC).
  • -y, --yes - Unattended import without confirmation (like hitting "y" from the command line).
Examples
Import full database
firestore-import --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json
Import to a specific path
firestore-import --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json --nodePath collectionA/document1/collectionCC

Clear

  • -a, --accountCredentials <path> - path to Google Cloud account credentials JSON file. If missing, will look at the GOOGLE_APPLICATION_CREDENTIALS environment variable for the path.
  • -n, --nodePath <path>- Path to database node to start (e.g. collectionA/docB/collectionC).
  • -y, --yes - Unattended clear without confirmation (like hitting "y" from the command line). Command will wait 5 seconds so you can Ctrl-C to stop.
  • -w, --noWait - Combine this with the --yes confirmation to not wait 5 seconds
Example
Clear everything under a specific node
firestore-clear --accountCredentials path/to/credentials/file.json --yes

Library

The underlying library can be used in a node or web application for importing and exporting data in a similar fashion

Exporting

import {firestoreExport} from 'node-firestore-import-export';
import * as firebase from 'firebase-admin';

firebase.initializeApp({
    apiKey: "AIza....",                             
    authDomain: "YOUR_APP.firebaseapp.com",         
    databaseURL: "https://YOUR_APP.firebaseio.com", 
    storageBucket: "YOUR_APP.appspot.com",          
    messagingSenderId: "123456789"                  
});

const collectionRef = firebase.firestore().collection('collectionA/docB/collectionC');

firestoreExport(collectionRef)
    .then(data=>console.log(data));

Importing

import {firestoreImport} from 'node-firestore-import-export';
import * as firebase from 'firebase-admin';

firebase.initializeApp({
    apiKey: "AIza....",                             
    authDomain: "YOUR_APP.firebaseapp.com",         
    databaseURL: "https://YOUR_APP.firebaseio.com", 
    storageBucket: "YOUR_APP.appspot.com",          
    messagingSenderId: "123456789"                  
});

const data = {
  docA: {
    name: 'bob',
    __collections__: {}
  },
  docB: {
    name: 'jill',
    __collections__: {}
  }
};

const collectionRef = firebase.firestore().collection('collectionA/docB/collectionC');

firestoreImport(data, collectionRef)
    .then(()=>console.log('Data was imported.'));

Clearing

import {firestoreClear} from 'node-firestore-import-export';
import * as firebase from 'firebase-admin';

firebase.initializeApp({
    apiKey: "AIza....",                             
    authDomain: "YOUR_APP.firebaseapp.com",         
    databaseURL: "https://YOUR_APP.firebaseio.com", 
    storageBucket: "YOUR_APP.appspot.com",          
    messagingSenderId: "123456789"                  
});

const collectionRef = firebase.firestore().collection('collectionA/docB/collectionC');

firestoreClear(collectionRef)
    .then(()=>console.log('Everything under collectionA/docB/collectionC was removed.'));

Contributions

Feel free to report bugs and make feature requests in the Issue Tracker, fork and create pull requests!

Inspiration

The command line was inspired heavily by SteadyEquipment's node-firestore-backup

Support on Beerpay

Hey dude! Help me out for a couple of 🍻!

Beerpay Beerpay

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].