Welcome to your ultimate guide for importing, exporting, and clearing Firestore data using the node-firestore-import-export tool! This handy tool ensures that your Firestore database operations are seamless and straightforward. Let’s dive into the details!
Table of Contents
Data Format
This tool exports data in a JSON format that preserves your collections and documents. Consider it like organizing a bookshelf; each book (document) is placed on the appropriate shelf (collection), and when you export, you take the whole shelf with you, without losing the order. Here’s a simplified example of the exported format:
{
__collections__: {
companies: {
docA: {
name: "Big Co",
employee_count: 2012,
created: {
__datatype__: "timestamp",
value: {
_seconds: 12343456,
_nanoseconds: 7890
}
}
}
}
}
}
Keep in mind that your imports must follow this very structure! A wrong import can lead to data chaos, much like mixing up the books on your neatly organized shelf.
Installation
To install this tool, you can use either npm or yarn:
npm install -g node-firestore-import-export
yarn global add node-firestore-import-export
Alternatively, you can download the source directly from GitHub:
git clone https://github.com/jlooslin/node-firestore-import-export.git
Retrieving Google Cloud Account Credentials
For the tool to authenticate properly, you need to retrieve Google Cloud account credentials:
- Visit the Firebase Console.
- Select your project.
- Navigate to Project Settings.
- Go to Service Accounts.
- Click Generate New Private Key. This file is essential for your operation.
Usage
Once you have everything set up, here is how you can use the tool.
Command Line
You can execute commands on the terminal. The path to the account credentials can be specified with the -a or --accountCredentials flag.
Export
Export data from your Firestore database using the command:
firestore-export --accountCredentials /path/to/credentials.json --backupFile backups/myDatabase.json
Import
To import data, use a similar command:
firestore-import --accountCredentials /path/to/credentials.json --backupFile backups/myDatabase.json
Clear
If you want to clear data, this command will do the trick:
firestore-clear --accountCredentials /path/to/credentials.json --yes
Library
If you’re working within a Node or web application, you can implement the library directly in your code. Here’s how:
import firestoreExport from 'node-firestore-import-export';
const data = await firestoreExport(collectionRef);
console.log(data);
Contributions
If you encounter any issues, feel free to report bugs or make feature requests in the Issue Tracker.
Troubleshooting
If you experience issues while using this tool, consider the following troubleshooting steps:
- Ensure that your Google Cloud account credentials are correctly set and accessible.
- Verify that the JSON structure of your import file matches the required format.
- Double-check the paths you are using in your commands.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

