Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
N

node-firestore-import-export

> 编程语言
Open source

Firestore data import and export

391 stars0 likes2 views
WebsiteGitHub

About

Firestore data import and export

node-firestore-import-export

Firestore data importing, exporting, and data clearing tool. Export a Firestore database, including collections and documents, while keeping the structure intact.

Table of Contents

  • Data format
  • Installation
  • Retrieving credentials
  • Usage
    • Command line
      • Export
      • Import
      • Clear
    • Library
      • Export
      • Import
      • Clear
  • Contributions

Data Format

Exports a json file with the following format:

…

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:

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

Installation

Install using npm.

bash
npm install -g node-firestore-import-export

or yarn

bash
yarn global add node-firestore-import-export

Alternatively download the source.

bash
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:

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

Export

  • -a, --accountCredentials `` - path to Google Cloud account credentials JSON file. If missing, will look at the GOOGLE_APPLICATION_CREDENTIALS environment variable for the path.
  • -b, --backupFile ``- Filename to store backup. (e.g. backups/full-backup.json). Defaults to firestore-export.json if missing.
  • -n, --nodePath ``- 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
bash
firestore-export --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json
Export with pretty printing
bash
firestore-export --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json --prettyPrint
Export from a specific path (and all its children/collections)
bash
firestore-export --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json --nodePath collectionA/document1/collectionCC

Import

  • -a, --accountCredentials `` - path to Google Cloud account credentials JSON file. If missing, will look at the GOOGLE_APPLICATION_CREDENTIALS environment variable for the path.
  • -b, --backupFile ``- Filename with backup data. (e.g. backups/full-backup.json).
  • -n, --nodePath ``- 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
bash
firestore-import --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json
Import to a specific path
bash
firestore-import --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json --nodePath collectionA/document1/collectionCC

Clear

  • -a, --accountCredentials `` - 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 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
bash
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

typescript
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

…

Clearing

…

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 :beers:!

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptbackupexportfirebasefirestore

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言