Coder Social home page Coder Social logo

jloosli / node-firestore-import-export Goto Github PK

View Code? Open in Web Editor NEW
382.0 6.0 78.0 1.13 MB

Firestore data import and export

Home Page: https://www.npmjs.com/package/node-firestore-import-export

License: MIT License

TypeScript 79.22% JavaScript 20.78%
firestore firebase import export backup restore

node-firestore-import-export's Introduction

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

node-firestore-import-export's People

Contributors

csimoes1 avatar davidverweij avatar dependabot-preview[bot] avatar dependabot-support avatar endran avatar hffmnn avatar jloosli avatar m417z avatar newyankeecodeshop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

node-firestore-import-export's Issues

Array DataType Should be Saved as an Array

Expected behavior

Array datatype should be saved as an array

Actual behavior

Array datatype saved as an object

Steps to reproduce the behavior

Just make a array datatype and import then export it again.

Gettings Error while Exporting Firestore

Expected behavior

Previously I use this library is working well, then when I use this is again it display an error like this:

The behavior for Date objects stored in Firestore is going to change
AND YOUR APP MAY BREAK.
To hide this warning and ensure your app does not break, you need to add the
following code to your app before calling any other Cloud Firestore methods:

  const firestore = new Firestore();
  const settings = {/* your settings... */ timestampsInSnapshots: true};
  firestore.settings(settings);

With this change, timestamps stored in Cloud Firestore will be read back as
Firebase Timestamp objects instead of as system Date objects. So you will also
need to update code expecting a Date to instead expect a Timestamp. For example:

  // Old:
  const date = snapshot.get('created_at');
  // New:
  const timestamp = snapshot.get('created_at');
  const date = timestamp.toDate();

Please audit all existing usages of Date when you enable the new behavior. In a
future release, the behavior will change to the new behavior, so if you do not
follow these steps, YOUR APP MAY BREAK.
Auth error:Error: invalid_grant
Auth error:Error: invalid_grant

The last two line are repeated several times.

Actual behavior

It doesn't display the error.

Steps to reproduce the behavior

Run firestore-export command as usual

Vulnerability warning for hoek package usage

Expected behavior

No errors or warnings on installation.

Actual behavior

Problems shown below.


$: sudo npm install --save-dev node-firestore-import-export

...

+ [email protected]
added 46 packages from 78 contributors and audited 25628 packages in 11.06s
found 2 moderate severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
sample-pie-shop:

...

                === npm audit security report ===

┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ node-firestore-import-export [dev]                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ node-firestore-import-export > firebase-functions >          │
│               │ jsonwebtoken > joi > hoek                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Prototype pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ hoek                                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ > 4.2.0 < 5.0.0 || >= 5.0.3                                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ node-firestore-import-export [dev]                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ node-firestore-import-export > firebase-functions >          │
│               │ jsonwebtoken > joi > topo > hoek                             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/566                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 2 moderate severity vulnerabilities in 25628 scanned packages
  2 vulnerabilities require manual review. See the full report for details.

Steps to reproduce the behavior

npm i node-firestore-import-export

Doc Reference

not an issue, but how can I use my own DocReference?

firestore-import NodeJS Geopoint conflict

Expected behavior

I am trying to upload a Geopoint data type in Node JS program but the upload is unsuccessful.
I expect the Geopoint datatype to be successfully updated.

Actual behavior

Argument "data" is not a valid Document. Detected an object of type "GeoPoint" that doesn't match the expected instance (found in field destinationCoordinates). Please ensure that the Firestore types you are using are from the same NPM package.

Configuration:

$ nvm ls
         v8.9.4
->      v8.13.0
         system

Steps to reproduce the behavior

  1. Create a script named firestore-import.js with the following content:
const firestoreImportExport = require('./node_modules/node-firestore-import-export');
function setupDBConnection(isReleaseConfig) {
  var sa = serviceAccount;
  var db = databaseURL;
  if (isReleaseConfig) {
    sa = prodServiceAccount;
    db = prodDatabaseURL;
  }
  admin.initializeApp({
    credential: admin.credential.cert(sa),
    databaseURL: db 
  });
}

async function main () {
    const rootDocumentPath = process.argv[2];
    const fullLocalPath = process.argv[3];
    setupDBConnection(false);
    
    const collectionRef = admin.firestore().collection(rootDocumentPath);
    const jsonString = fs.readFileSync(fullLocalPath, 'utf8');
    const serializedData = JSON.parse(jsonString, null, 2);

  await firestoreImportExport.firestoreImport(serializedData, collectionRef, false).then( () => {
        console.log(`{ ${fullLocalPath} } data was imported into root collection { ${rootDocumentPath}} 
      }`);
  });
}
  1. Create a test.json file:
{
  "sample_data": {
    "destinationCoordinates": {
      "__datatype__": "geopoint",
      "value": {
          "_latitude": 48.830226,
          "_longitude": 2.370378
      }
    },
    "__collections__": {}
  }
}
  1. Launch the node program:
$ node firestore-import.js test test.json

Everything is fine if I remove the "_datatype_": "geopoint" thing except it is not stored as a Geopoint into Firestore.
When I add it I am getting the above error.

firestore-export no json file created

Hello,

I ty to make a backup of my Firestore db (free plan). I did

$ yarn global add  node-firestore-import-export

then I generated and dloaded a new private key from my Firebase admin SDK

I chdir to the directory containing the newly generated private key and the ./backups directory and issued the firestore-export command from the windows terminal:

$ firestore-export --accountCredentials "./ifactuur-v2-firebase-admins 
dk-c7cfj-4066d9df36.json" --backupFile "./backups/ifactuur-v2.json" -- 
prettyPrint

I get this in the terminal

Retrieving documents from bills
Retrieving documents from companies
Retrieving documents from invoices
Retrieving documents from registrations
Retrieving documents from status
Retrieving documents from users
Retrieving documents from vatrates
MINGW64:/e/www/firestore-import-export[24924]: c:\ws\src\node_http2.cc:893: Assertion `(flags_ & SESSION_STATE_READING_STOPPED) != (0)' failed.
 1: 00007FF648FDDD8A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4506
 2: 00007FF648FB8886 node::MakeCallback+4534
 3: 00007FF648FB893F node::MakeCallback+4719
 4: 00007FF648F5CA35 EVP_CIPHER_CTX_get_cipher_data+114517
 5: 00007FF648F60BD1 EVP_CIPHER_CTX_get_cipher_data+131313
 6: 00007FF648EA6D76 DH_get0_q+14022
 7: 00007FF648EA4AD8 DH_get0_q+5160
 8: 00007FF648EA7D61 DH_get0_q+18097
 9: 00007FF648F010B1 RSA_meth_get_flags+753
10: 00007FF64900E203 uv_tcp_getpeername+1315
11: 00007FF649021457 uv_dlerror+2007
12: 00007FF6490223E8 uv_run+232
13: 00007FF648FBFE7E node::NewContext+1390
14: 00007FF648FC048B node::NewIsolate+603
15: 00007FF648FC08E7 node::Start+823
16: 00007FF648E6F3CC node::MultiIsolatePlatform::MultiIsolatePlatform+604
17: 00007FF649AB863C v8::internal::compiler::OperationTyper::ToBoolean+129516
18: 00007FFC33CE7BD4 BaseThreadInitThunk+20
19: 00007FFC3564CED1 RtlUserThreadStart+33

The first few lines are correct - these are the collections I want to backup but no backup file 'ifactuur-v2.json' is created anywhere...
I'm on a W10 environment...

Am I missing something?
Thanks,

Marc

firestoreImport method manipulates its data input

Expected behavior

Calling firestoreImport multiple times while passing an object by reference in it results in identical write operations.

Actual behavior

firestoreImport fiddles around with DELETE operations on the object passed as the first argument. This leads to an unexpected behavior which at least should be well documented.

Steps to reproduce the behavior

const dump = {name: 'Alice', __collections__: {jobs: {123: {name: 'doctor'}}}};
await firestoreImport({['id1']: dump}, db.collection('user')); // works as expected
await firestoreImport({['id2']: dump}, db.collection('user')); // doesn't write sub-collections
await firestoreImport({['id3']: dump}, db.collection('user')); // doesn't write sub-collections
// workaround
const getDump = () => ({name: 'Alice', __collections__: {jobs: {123: {name: 'doctor'}}}});
await firestoreImport({['id1']: getDump()}, db.collection('user')); // works as expected
await firestoreImport({['id2']: getDump()}, db.collection('user')); // works as expected
await firestoreImport({['id3']: getDump()}, db.collection('user')); // works as expected

Export timestamp [Object] value

Expected behavior

Display the timestamp value: 18 de março de 2019 18:30:00 UTC-3

Actual behavior

Shows like this: end: { datatype: 'timestamp', value: [Object] },

Steps to reproduce the behavior

Export using library a collection with timestamp

Thanks

Error on running import command

Expected behavior

Importing data from the .json file to the firestore database.

Actual behavior

Getting the error while running the correct command as per documentation.

error: unknown option --backupFile userSettings.json'`

Steps to reproduce the behavior

Running the command:

firestore-import --accountCredentials serviceAccountKey.json --backupFile userSettings.json --nodePath userSettings

Import fails

Expected behavior

The import should have run

Actual behavior

➜  node-firestore-import-export git:(master) node ./dist/bin/firestore-import.js --accountCredentials ~/Downloads/staging-cd6a5-firebase-adminsdk-771d4477a1.json --backupFile mb_staging.json
/Users/harit/bl/sources/webs/q2/node-firestore-import-export/dist/bin/firestore-import.js:55
    const [data, pathReference] = res;
          ^

SyntaxError: Unexpected token [
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:146:18)
    at node.js:404:3
➜  node-firestore-import-export git:(master)

Steps to reproduce the behavior

  • Checkout the codebase
  • Run the following commands
npm install && npm run build
  • export your data using README.md. This command works fine.
  • Import your data using README.md command. This fails.
➜  node-firestore-import-export git:(master) node ./dist/bin/firestore-import.js --accountCredentials ~/Downloads/staging-cd6a5-firebase-adminsdk-zk1to-771d4477a1.json --backupFile mb_staging.json
/Users/harit/bl/sources/webs/q2/node-firestore-import-export/dist/bin/firestore-import.js:55
    const [data, pathReference] = res;
          ^

SyntaxError: Unexpected token [
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:146:18)
    at node.js:404:3
➜  node-firestore-import-export git:(master)

Additionally, in README.md, the command for import has a typo, the second command import says export instead of import. Thanks

Clear database

Feature request

For my test setup I would like to be able to clear the entire db before importing. Something like:
firestore-clear -a firebase-admin.json -y.

Is this something you would considering added, or merge in if I would have a PR?

Not working correctly in Firebase Functions

Expected behavior

Firestore Database backup .json file should be as is if we use console commands.

Actual behavior

Backup .json file contains wrong data. No datatype entities inside.

Steps to reproduce the behavior

Inside Firebase Functions:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore()
const firestoreImportExport = require('node-firestore-import-export')

exports.createFirestoreBackup = functions.https.onRequest((request, response) => {
firestoreImportExport.firestoreExport(db).then(data => {
// data is wrong
})
})

INVALID_ARGUMENT: Cannot convert an array value in an array value

Expected behavior

Exported file should be imported

Actual behavior

Got error:
{ Error: 3 INVALID_ARGUMENT: Cannot convert an array value in an array value.
at new createStatusError ( ... \node_modules\grpc\src\client.js:64:15)
at ... \node_modules\grpc\src\client.js:583:15
code: 3,
metadata: Metadata { _internal_repr: {} },
details: 'Cannot convert an array value in an array value.' }

Most of the collections got imported with documents, but others are missing (those with this error).
What is causing this?

Steps to reproduce the behavior

Error: Argument "seconds" is not a valid integer. While Importing

Expected behavior

Make an normal import of the TimeStamp type.

Actual behavior

When trying to import a export made on 0.10.2 I get this error:

Error: Argument "seconds" is not a valid integer.
Error: Argument "seconds" is not a valid integer.
at Validator.(anonymous function).values [as isInteger] (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@google-cloud\firestore\build\src\validate.js:99:27)
at new Timestamp (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@google-cloud\firestore\build\src\timestamp.js:115:18)
at C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\dist\lib\helpers.js:47:33
at Array.map ()
at Object.unserializeSpecialTypes (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\dist\lib\helpers.js:41:23)
at C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\dist\lib\import.js:65:42
at Array.map ()
at C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\dist\lib\import.js:55:22
at Array.map ()
at setDocuments (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\dist\lib\import.js:53:32)

Steps to reproduce the behavior

Make an export of the DB that contains TimeStamp types and then try to import it.

THanks in advance.

Memory issues when trying to export large datasets

We use node-firestore-import-export on a daily basis for im/export of several test Firestore instances. Next to that we use it as a secondary backup path for production. Or production database is growing quite large, and we run into memory issues when resolving 20.000+ promises simultaneously.

Expected behavior

A successful export via Cloud Function

Actual behavior

Error: memory limit exceeded. Function invocation was interrupted.
Error: function crashed out of request scope Function invocation was interrupted.

Steps to reproduce the behavior

Create a DB with several collections with far over 20.000 documents, and try to run an export via a Cloud Function.

How to export everything in Node

The CLI exports everything from the entire database, but it seems that node can only export specific collections. Is there anyway to easily export everything in node at once? Cheers.

Error: Argument "data" is not a valid Document

Expected behavior

Commandline export and programmatic import does not cause an error.

Actual behavior

It does cause an error.

Steps to reproduce the behavior

  1. Make sure there is a Timestamp in the database.

  2. run
    firestore-export --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json

  3. programmatically import by the example in the readme.md:

const {firestoreImport} = require('node-firestore-import-export');
const FirestoreData = require("./backups/myDatabase.json");
const admin = require('firestore-admin');

let serviceAccount = require('service-account.json');
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "db-url"
});

firestore = admin.firestore();
const settings = {timestampsInSnapshots: true};
firestore.settings(settings);

firestoreImport(FirestoreData, firestore);
  1. Error is thrown as follows:
(node:8088) UnhandledPromiseRejectionWarning: Error: Argument "data" is not a valid Document. Detected an object of type "Timestamp" that doesn't match the expected instance. Please ensure that the Firestore types you are using are from the same NPM package.
    at Validator.(anonymous function).values [as isDocument] (C:\Users\me\projects\maklr-backend\tools\node_modules\@google-cloud\firestore\build\src\validate.js:99:27)
    at WriteBatch.set (C:\Users\me\projects\maklr-backend\tools\node_modules\@google-cloud\firestore\build\src\write-batch.js:232:25)
    at C:\Users\me\projects\maklr-backend\tools\node_modules\node-firestore-import-export\dist\lib\import.js:68:19
    at Array.map (<anonymous>)
    at C:\Users\me\projects\maklr-backend\tools\node_modules\node-firestore-import-export\dist\lib\import.js:57:22
    at Array.map (<anonymous>)
    at setDocuments (C:\Users\me\projects\maklr-backend\tools\node_modules\node-firestore-import-export\dist\lib\import.js:55:32)
    at importData (C:\Users\me\projects\maklr-backend\tools\node_modules\node-firestore-import-export\dist\lib\import.js:28:43)
    at importAuthUsers.then (C:\Users\me\projects\maklr-backend\tools\restoreEnvironment.js:85:20)
    at <anonymous>
(node:8088) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8088) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I've seen issue #36 , which seems to be similar to my difficulties. However, the issue mentions that the issue is fixed. I am using the most recent version (0.13.2) so I presume it's either not entirely fixed, or it's the same error but with a different cause.

firestore-clear wait for 5 seconds

Expected behavior

I expected firestore-clear -a xxx.json -y not to wait for 5 seconds.
I think this is too opinionated, or at lease have an option for this.
I just want to flush all and setUp the next test case. :)

Actual behavior

It's waiting for 5 seconds before operation start.

JSON file too big ?

Expected behavior

Try to upload a big JSON file (~20 MB, ~), full data uploaded in Firestore

Actual behavior

Got an error :
{ Error: 4 DEADLINE_EXCEEDED: Deadline Exceeded ... }
in client.js:64:15
in client.js:583:15

But i also got the "All done" message ... Strange
Is this a limit because of the size of the file or the time it takes to upload ?

Steps to reproduce the behavior

implementation on browser + ionic

Expected

Hi!

I would like to be able to use this library in my ionic project, but I do not know how to configure it.

You could help me get more explicitly about where to place an index.html, with a js .. file so I can use the library.

I downloaded the github example, I have my firestore file but I do not know how to put any code in it.

I am sorry that this comment is very novice, but I have tried many things and I can not find the way

cannot convert an array value in an array value. ERROR

Expected behavior

this is the data i am adding to a field:
[ [ '-LXRXPFgA6sC9Mg0GQMt', 2, 'Sushi premium' ], [ '-LXRSAp3jpB8EUbZU-0c', 1, 'Caramel Glazed Donuts' ] ]

Actual behavior

3 INVALID_ARGUMENT: Cannot convert an array value in an array value.
at Object.exports.createStatusError (/user_code/node_modules/firebase-admin/node_modules/grpc/src/common.js:91:15)
at Object.onReceiveStatus (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client_interceptors.js:1204:28)
at InterceptingListener._callNext (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client_interceptors.js:568:42)
at InterceptingListener.onReceiveStatus (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client_interceptors.js:618:8)
at callback (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client_interceptors.js:845:24)

Steps to reproduce the behavior

add this to a field of a doc with cloud function https [ [ '-LXRXPFgA6sC9Mg0GQMt', 2, 'Sushi premium' ], [ '-LXRSAp3jpB8EUbZU-0c', 1, 'Caramel Glazed Donuts' ] ]

Special characters bug on export

Expected behavior

Export displaying the special character, examples: café,pedaço, açúcar

Actual behavior

Exporting like this: caf├®,l peda├ºo, a├º├║car

Steps to reproduce the behavior

Export using library with special character

Bandwidth Exhausted

Expected behavior

firestore-import working correctly - i.e. importing contents of json file created by firestore-export back into firestore.

Actual behavior

The import works partially - a few seconds after starting I get these errors

Writing documents for dev/CPUqFGRmPqsctsCovM7n/keys
Writing documents for dev/CPUqFGRmPqsctsCovM7n/programCounters
Writing documents for dev/CPUqFGRmPqsctsCovM7n/sheets
Writing documents for dev/CPUqFGRmPqsctsCovM7n/varieties
Error: 8 RESOURCE_EXHAUSTED: Bandwidth exhausted
    at Object.callErrorFromStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
    at Http2CallStream.outputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:116:74)
    at Http2CallStream.maybeOutputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:155:22)
    at Http2CallStream.endCall (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:141:18)
    at ClientHttp2Stream.<anonymous> (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:403:22)
    at ClientHttp2Stream.emit (events.js:219:5)
    at emitErrorCloseNT (internal/streams/destroy.js:76:8) {
  code: 8,
  details: 'Bandwidth exhausted',
  metadata: Metadata { internalRepr: Map {}, options: {} }
}
Error: 13 INTERNAL: Received RST_STREAM with code 2
    at Object.callErrorFromStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
    at Http2CallStream.outputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:116:74)
    at Http2CallStream.maybeOutputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:155:22)
    at Http2CallStream.endCall (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:141:18)
    at ClientHttp2Stream.<anonymous> (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:403:22)
    at ClientHttp2Stream.emit (events.js:219:5)
    at emitErrorCloseNT (internal/streams/destroy.js:76:8) {
  code: 13,
  details: 'Received RST_STREAM with code 2',
  metadata: Metadata { internalRepr: Map {}, options: {} }
}
Error: 13 INTERNAL: Received RST_STREAM with code 2
    at Object.callErrorFromStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
    at Http2CallStream.outputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:116:74)
    at Http2CallStream.maybeOutputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:155:22)
    at Http2CallStream.endCall (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:141:18)
    at ClientHttp2Stream.<anonymous> (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:403:22)
    at ClientHttp2Stream.emit (events.js:219:5)
    at emitErrorCloseNT (internal/streams/destroy.js:76:8) {
  code: 13,
  details: 'Received RST_STREAM with code 2',
  metadata: Metadata { internalRepr: Map {}, options: {} }
}
Error: 8 RESOURCE_EXHAUSTED: Bandwidth exhausted
    at Object.callErrorFromStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
    at Http2CallStream.outputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:116:74)
    at Http2CallStream.maybeOutputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:155:22)
    at Http2CallStream.endCall (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:141:18)
    at ClientHttp2Stream.<anonymous> (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:403:22)
    at ClientHttp2Stream.emit (events.js:219:5)
    at emitErrorCloseNT (internal/streams/destroy.js:76:8) {
  code: 8,
  details: 'Bandwidth exhausted',
  metadata: Metadata { internalRepr: Map {}, options: {} }
}
Error: 8 RESOURCE_EXHAUSTED: Bandwidth exhausted
    at Object.callErrorFromStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
    at Http2CallStream.outputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:116:74)
    at Http2CallStream.maybeOutputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:155:22)
    at Http2CallStream.endCall (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:141:18)
    at ClientHttp2Stream.<anonymous> (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:403:22)
    at ClientHttp2Stream.emit (events.js:219:5)
    at emitErrorCloseNT (internal/streams/destroy.js:76:8) {
  code: 8,
  details: 'Bandwidth exhausted',
  metadata: Metadata { internalRepr: Map {}, options: {} }
}
Error: 8 RESOURCE_EXHAUSTED: Bandwidth exhausted
    at Object.callErrorFromStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
    at Http2CallStream.outputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:116:74)
    at Http2CallStream.maybeOutputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:155:22)
    at Http2CallStream.endCall (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:141:18)
    at ClientHttp2Stream.<anonymous> (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:403:22)
    at ClientHttp2Stream.emit (events.js:219:5)
    at emitErrorCloseNT (internal/streams/destroy.js:76:8) {
  code: 8,
  details: 'Bandwidth exhausted',
  metadata: Metadata { internalRepr: Map {}, options: {} }
}
Error: 13 INTERNAL: Received RST_STREAM with code 2
    at Object.callErrorFromStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
    at Http2CallStream.outputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:116:74)
    at Http2CallStream.maybeOutputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:155:22)
    at Http2CallStream.endCall (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:141:18)
    at ClientHttp2Stream.<anonymous> (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:403:22)
    at ClientHttp2Stream.emit (events.js:219:5)
    at emitErrorCloseNT (internal/streams/destroy.js:76:8) {
  code: 13,
  details: 'Received RST_STREAM with code 2',
  metadata: Metadata { internalRepr: Map {}, options: {} }
}
Error: 13 INTERNAL: Received RST_STREAM with code 2
    at Object.callErrorFromStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
    at Object.onReceiveStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
    at Http2CallStream.outputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:116:74)
    at Http2CallStream.maybeOutputStatus (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:155:22)
    at Http2CallStream.endCall (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:141:18)
    at ClientHttp2Stream.<anonymous> (/home/ec2-user/.nvm/versions/node/v13.3.0/lib/node_modules/node-firestore-import-export/node_modules/@grpc/grpc-js/build/src/call-stream.js:403:22)
    at ClientHttp2Stream.emit (events.js:219:5)
    at emitErrorCloseNT (internal/streams/destroy.js:76:8) {
  code: 13,
  details: 'Received RST_STREAM with code 2',
  metadata: Metadata { internalRepr: Map {}, options: {} }
}
All done 🎉

Some data is imported into the firestore database, but other data is not imported.

Steps to reproduce the behavior

Using version 1.1.0

Running command
/home/ec2-user/.nvm/versions/node/v13.3.0/bin/firestore-import -a ~/pc-test-firebase-adminsdk-5relp-daf7fa32cf.json -b backup-202005251534.json

The Firestore project is using the Blaze plan

400 undefined: Getting metadata from plugin failed with error: invalid_grant: Invalid JWT

Expected behavior

Should export data from Firestore to my computer

Actual behavior

Throws this error:
400 undefined: Getting metadata from plugin failed with error: invalid_grant: Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim.

Steps to reproduce the behavior

~/repositories/myProject$ firestore-export --accountCredentials my-project-dev-7b0c5b821785.json --backupFile myDatabase.json

400 undefined: Getting metadata from plugin failed with error: invalid_grant: Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim.

What could be causing this issue?

Cannot read property 'projectId' of undefined

Expected behavior

Import backupFile

Actual behavior

TypeError: Cannot read property 'projectId' of undefined
at C:\Users\micha\AppData\Roaming\npm\node_modules\node-firestore-import-export\dist\bin\firestore-import.js:69:32

Steps to reproduce the behavior

--accountCredentials C:\Users\micha\Downloads\credentials.json --backupFile C:\Users\micha\Desktop\db.json

Getting error TypeError: startingRef.get is not a function

firestore-export --accountCredentials ..\sales-buddy-v2-firebase-adminsdk-6euxz-526882fedf.json --backupFile myDatabase1.json --prettyPrint
TypeError: startingRef.get is not a function

I'm a newbie, so might be missing something basic. Please help

firestore_import_deadlineExceeded

I used this command line:
firestore-import --accountCredentials firebase-adminsdk-key.json --backupFile myDatabase.json

where : myDatabase.json is a json I generated from a firestore database (using the export command)

the issue I get is:
{ Error: 4 DEADLINE_EXCEEDED: Deadline exceeded
at Object.callErrorFromStatus (C:\Users\HP\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@grpc\grpc-js\build\src\call.js:30:26)
at Http2CallStream.call.on (C:\Users\HP\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@grpc\grpc-js\build\src\client.js:96:33)
at Http2CallStream.emit (events.js:194:15)
at process.nextTick (C:\Users\HP\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@grpc\grpc-js\build\src\call-stream.js:100:22)
at process._tickCallback (internal/process/next_tick.js:61:11)
code: 4,
details: 'Deadline exceeded',
metadata: Metadata { internalRepr: Map {}, options: {} } }

how to fix it?

Error: Invalid use of type "undefined" as a Firestore argument.

Expected behavior

Make an normal import of the TimeStamp type.

Actual behavior

When trying to import a export made on 0.10.3 I get this error:

Error: Invalid use of type "undefined" as a Firestore argument.
Error: Invalid use of type "undefined" as a Firestore argument.
at Object.customObjectError (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@google-cloud\firestore\build\src\validate.js:168:16)
at Serializer.encodeValue (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@google-cloud\firestore\build\src\serializer.js:145:26)
at Serializer.encodeFields (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@google-cloud\firestore\build\src\serializer.js:53:34)
at Serializer.encodeValue (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@google-cloud\firestore\build\src\serializer.js:138:44)
at Serializer.encodeFields (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@google-cloud\firestore\build\src\serializer.js:53:34)
at Serializer.encodeValue (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@google-cloud\firestore\build\src\serializer.js:138:44)
at Serializer.encodeFields (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@google-cloud\firestore\build\src\serializer.js:53:34)
at Function.fromObject (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@google-cloud\firestore\build\src\document.js:141:53)
at WriteBatch.set (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules@google-cloud\firestore\build\src\write-batch.js:241:54)
at C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\dist\lib\import.js:66:19

Steps to reproduce the behavior

Make an export of the DB and then try to import it.

Wrong geopoint, and timestamp data types when exporting.

Expected behavior

The result of exporting geopoint, and timestamp data types are fields of the same types.

Actual behavior

When I export my database from collectionA/document1/

Within document1 I have 1 more collection that contain geopoint, and timestamp data types that are exported correctly. But I also have fields within document1 that have geopoint (latlng), and timestamp (createdAt, updatedAt) data types that are exported as arrays.

Attached is image of the JSON resulting from the export.
Thank you very much.

export-json

Steps to reproduce the behavior

importing document references shows as an object

Expected behavior

After import, document references should be proper firestore references

expected

Actual behavior

After import, reference objects are actually key/values object representations of their export object
2

Steps to reproduce the behavior

  1. export firestore db using the firestore export.js file
  2. import the backup file produced in step 1 back to the db
  3. All references are simply POJOs (JSON)

'where' query dont work on 0.14

const usersRef = db.collection(users).where('projectKey', '==', projectKey);
firestoreExport(usersRef).then ....

the 'where' query dont work on 0.14
but works on 0.12

Steps to reproduce the behavior

try a where query on a colletion

String formatted timestamps are not correctly detected during import

Expected behavior

  describe("unserializeSpecialTypes", () => {
    before(() => {
      admin.initializeApp();
    });

    it("should convert parsable date string timestamps", () => {
      const dateStringTypes = {
        iso8601: {
          __datatype__: "timestamp",
          value: "2020-06-01T04:59:03-07:00"
        }
      };

      const results = unserializeSpecialTypes(dateStringTypes);
      expect(results.iso8601).to.be.an.instanceof(admin.firestore.Timestamp);
    });
  });

Actual behavior

Helpers
       unserializeSpecialTypes
         should convert parsable date string timestamps:
     Error: Value for argument "seconds" is not a valid integer.

Steps to reproduce the behavior

Attempt to import a Date.parse()-able timestamp value.

Subcollections displayed as [Object]

Expected behavior

Show subcollection data

Actual behavior

Exporting like:

uid:
{ email: '',
collections:
{ one: [Object],
two: [Object],
three: [Object],
four: [Object] } },

Steps to reproduce the behavior

Export using library with subcollections

Support document ID generation by firestore

Please correct me if I'm wrong, but as far as I can tell, this library does not currently offer the option to allow firestore to generate ID for documents in collection or subcollections, rather the ID has to be specified upfront in the data that is being imported.

If this is currently not supported, I suggest a feature where a token like <docId> can be inserted into JSON that is being imported, and the library will then delegate to firestore to generate an ID for that document.

If I've missed an existing feature please let me know. Otherwise, let's discuss how this should work.

firestore-clear CLI is not working

Expected behavior

To delete my entire DB information

Actual behavior

Error:
'firestore-clear' is not recognized as an internal or external command, operable program or batch file.

Steps to reproduce the behavior

Just execute the command.
firestore-import works perfectly
firestore-export works perfectly.

firestore warning in console

About to import data config/firestore/settings.json to the 'undefined' firestore at 'settings'.
=== Warning: This will overwrite existing data. Do you want to proceed? ===
firestore-import: Proceed with import? [y/N] : y
Writing documents for settings

The behavior for Date objects stored in Firestore is going to change
AND YOUR APP MAY BREAK.
To hide this warning and ensure your app does not break, you need to add the
following code to your app before calling any other Cloud Firestore methods:

const firestore = new Firestore();
const settings = {/* your settings... */ timestampsInSnapshots: true};
firestore.settings(settings);

With this change, timestamps stored in Cloud Firestore will be read back as
Firebase Timestamp objects instead of as system Date objects. So you will also
need to update code expecting a Date to instead expect a Timestamp. For example:

// Old:
const date = snapshot.get('created_at');
// New:
const timestamp = snapshot.get('created_at');
const date = timestamp.toDate();

Please audit all existing usages of Date when you enable the new behavior. In a
future release, the behavior will change to the new behavior, so if you do not
follow these steps, YOUR APP MAY BREAK.

Directly exporting "unreachable" sub-collections stopped working

The issue is relevant to my previous issue here: #42

I previously reported that if I have a user whose document doesn't exist, but there is a sub-collection with documents, the sub-collection of this user is not exported.

You said that it wasn't possible to fix, so I wrote a script to do manual export per "unreachable" sub-collection, similar to:

const collectionRef = admin.firestore().collection('users/' + userId + '/semesters');
firestoreImportExport.firestoreExport(collectionRef).then(/*...*/);

It worked at least until a month ago. But today I discovered that it stopped working. And it seems that it stopped working only for such "unreachable" sub-collections, i.e. sub-collections that neither get exported via the full database export.

I understand that it's a regression on the Firestore end, but perhaps you have a workaround for this. If not, it would be great if you could send the Firestore team a report about this, or alternatively point me to the regressed API call and I'll try to contact them.

As of now, I don't have a way to do a full backup of my project's database, which kinda sucks :(

Restore issue

I am trying to restore my database but keep running into this error.

Missing: backupFile - Filename to store backup. (e.g. backups/full-backup.json). Usage: firestore-import [options]

Backing up works perfect. Here is the command line I am using
firestore-import --accountCredentials XXX —backupFile firestore-export.json

Note this is the backup command:
firestore-export --accountCredentials XXX --backupFile firestore-export.json

The file is in the same place.

Allow to change batchExecutor's batchSize via command line

Currently the import/export tasks are executed in parallel in batches of 50:

const batchExecutor = async function<T>(promises: Promise<T>[], batchSize: number = 50) {

This number can't be changed via command line, only by modifying the source code.

50 is too large for my computer - the export task times out and fails. Changing it to 5 fixes the issue for me. It would be nice to have an option to control this number without having to fork the package.

import failed

export succeeded but import failed.

firestore-export --accountCredentials prod.json --backupFile myDatabase.json
=> myDatabase.json created
firestore-import --accountCredentials dev.json --backupFile myDatabase.json
TypeError: Cannot read property 'firestore' of undefined

"Export full database" doesn't export sub-collections of empty collections

Look at the screenshot below for an example. I have a user, id 0DLt5O1ma0d..., whose document doesn't exist, but there is a sub-collection with documents. When doing full database export (firestore-export --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json), the sub-collection of this user is not exported.

image

Error: Argument "data" is not a valid Document. Cannot use "undefined" as a Firestore value (found in field user.userRef).

Expected behavior

Make an normal import of the TimeStamp type.

Actual behavior

When trying to import a export made on 0.10.4 I get this error:

Error: Argument "data" is not a valid Document. Cannot use "undefined" as a Firestore value (found in field user.userRef).
Error: Argument "data" is not a valid Document. Cannot use "undefined" as a Firestore value (found in field user.userRef).
at Validator.(anonymous function).values [as isDocument] (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules\firebase-admin\node_modules@google-cloud\firestore\build\src\validate.js:92:27)
at WriteBatch.set (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\node_modules\firebase-admin\node_modules@google-cloud\firestore\build\src\write-batch.js:225:25)
at C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\dist\lib\import.js:66:19
at Array.map ()
at C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\dist\lib\import.js:55:22
at Array.map ()
at setDocuments (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\dist\lib\import.js:53:32)
at Object.importData [as default] (C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\dist\lib\import.js:27:43)
at C:\Users\Pc\AppData\Roaming\npm\node_modules\node-firestore-import-export\dist\bin\firestore-import.js:96:28
at

PD: The field userRef that is mentioned in the error is of type reference, like this "userRef: users/oRVksmPWOsXPJNFrmbGP359t6J03"

Steps to reproduce the behavior

Make an export of the DB and then try to import it.

firestore-import throws TypeError exception

Expected behavior

firestore-import should upload the backup file to Firestore

Actual behavior

firestore-import throws a TypeError exception:

TypeError: Cannot read property 'projectId' of undefined TypeError: Cannot read property 'projectId' of undefined at /home/bscholtz/.nvm/versions/node/v9.1.0/lib/node_modules/node-firestore-import-export/dist/bin/firestore-import.js:71:33 at <anonymous>

Steps to reproduce the behavior

Running firestore-export works, this indicates the credentials are set up correctly. When running firestore-import, the exception above is thrown.

Optionally mute console.log

Expected behavior

Only error logs show to the console

Actual behavior

Every action prints to the console

Steps to reproduce the behavior

Simply run the code. It results in console.log() calls being made when retrieving documents from each collection. This results in a lot of log/terminal spam that is not useful.

Can there at minimum be a setting to disable all console logging other than errors, or perhaps just remove the informational console.log() statements?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.