Skip to content

shadowwalker/firestore-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

firestore-tools CLI

A CLI for firestore data management.

size dependencies downloads license

Features

  • export data from firestore into json
  • import data into firestore from json

Must Read Before Use

firestore-tools CLI is not suitable to use directly on production database or large datasets. It's recommended to use during concept validation, test, data mock of project development.

Getting Started

Install

Install firestore-tools globally

yarn global add firestore-tools
# or
npm install --global firestore-tools

Alternatively, you can run it using npx without install, for example

npx firestore-tools ...

Get Firebase Service Account Private Key JSON file

Go to GCP IAM & Identity Console, select your firebase project on the top. Then select the firebase adminsdk service account, create a private key and download the JSON file. This file will be used to authenticate the CLI to access firestore database with admin access.

firebase-service-account

Export

# if arguments supplied from command line, you will be prompt to give that information
firestore-tools export

# you can also supply arguments from command line
firestore-tools export --key project-id-36257f6a2dcc.json --json data.json -spaces 2 --collections Users,Posts
  • export - command name, could also use alias e
  • key - required service account private key json file
  • json - output JSON file
  • spaces - indentation in JSON file
  • collections - comma separated top level collections to export

Import

# if arguments supplied from command line, you will be prompt to give that information
firestore-tools import

# you can also supply arguments from command line
firestore-tools import --key project-id-36257f6a2dcc.json --json data.json
  • import - command name, could also use alias i
  • key - required service account private key json file

JSON

firestore-tools use JSON data schema to map the data in firestore database, below is an example.

Any key prefixed with lower dash _ has special meaning of indicating data type and structure.

{
  "collection-id": {
    "document-id": {
      "_data": {
        "geopoint": {
          "_latitude": 47.7558843,
          "_longitude": 122.2646634
        },
        "null": null,
        "number": 123456,
        "array": [
          "hello",
          "world"
        ],
        "reference": {
          "_segments": [
            "Test",
            "referred"
          ]
        },
        "map": {
          "field": "hellofield"
        },
        "timestamp": {
          "_seconds": 1580848496,
          "_nanoseconds": 0
        },
        "boolean": true,
        "string": "helloworld"
      },
      "_collections": {
        "subcollection-id": {
          "document-id": {
            "_data": {
              "text": "hello"
            },
            "_collections": {}
          }
        }
      }
    }
  }
}

About

firestore CLI tools for data management 🛠

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published