question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Argument "data" is not a valid Document

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bilalkhanamincommented, Jan 26, 2022

I just put this structure data and it worked.

{
  "test": {
    "first-key": {
      "website": "dalenguyen.me",
      "date": {
        "_seconds": 1534046400,
        "_nanoseconds": 0
      },
      "schedule": {
        "time": {
          "_seconds": 1534046400,
          "_nanoseconds": 0
        }
      },
      "three": {
        "level": {
          "time": {
            "_seconds": 1534046400,
            "_nanoseconds": 0
          }
        }
      },
      "custom": {
        "lastName": "Nguyen",
        "firstName": "Dale"
      },
      "location": {
        "_latitude": 49.290683,
        "_longitude": -123.133956
      },
      "locationNested": {
        "geopoint": {
          "_latitude": 49.290683,
          "_longitude": -123.133956
        }
      },
      "locations": [
        {
          "_latitude": 50.290683,
          "_longitude": -123.133956
        },
        {
          "_latitude": 51.290683,
          "_longitude": -123.133956
        }
      ],
      "email": "dungnq@itbox4vn.com",
      "secondRef": "test/second-key",
      "arrayRef": ["test/second-key", "test/second-key"],
      "nestedRef": {
        "secondRef": "test/second-key"
      },
      "subCollection": {
        "test/first-key/details": {
          "33J2A10u5902CXagoBP6": {
            "dogId": "2",
            "dogName": "hello"
          },
          "MSZTWEP7Lewx0Qr1Mu5s": {
            "dogName": "lala",
            "dogId": "2"
          }
        },
        "test/first-key/contacts": {
          "33J2A10u5902CXagoBP6": {
            "contactId": "1",
            "name": "Dale Nguyen"
          },
          "MSZTWEP7Lewx0Qr1Mu5s": {
            "contactId": "2",
            "name": "Yen Nguyen"
          }
        }
      }
    },
    "second-key": {
      "website": "google.com",
      "date": {
        "_seconds": 1534262435,
        "_nanoseconds": 0
      },
      "custom": {
        "lastName": "Potter",
        "firstName": "Harry"
      },
      "location": {
        "_latitude": 49.290683,
        "_longitude": -123.133956
      },
      "email": "test@dalenguyen.me"
    }
  }
}
0reactions
joelclimbsthingscommented, Apr 7, 2021

+1, came across the same issue when trying to import anything with timestamps:

      "activatedAt": {
         "__datatype__": "timestamp",
         "value": {
            "_seconds": 1609184426,
            "_nanoseconds": 734000000
         }
      },
Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Error: Argument "data" is not a valid Document. Input ...
Error : Argument "data" is not a valid Document. Input is not a plain JavaScript object. when updating a document, using firebase admin...
Read more >
Value for argument "data" is not a valid Firestore document ...
Error : Value for argument "data" is not a valid Firestore document. Detected an object of type "DocumentReference" that doesn't match the expected...
Read more >
Firestore error: Error: Value for argument "data" is not a valid ...
But it was occured error like below. Error: Value for argument "data" is not a valid Firestore document. Input is not a plain...
Read more >
R Error in FUN : invalid 'type' (character) of argument
The previous output of the RStudio console shows that our example data is a vector consisting of five elements. Example 1: Reproduce the...
Read more >
Argument "data" is not a valid Document. Input is not a plain ...
I had same problem, in my case I'd forgot to add Content-Type:application/json to my header when sending request, and then the object was...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found