jloosli / node-firestore-import-export

Firestore data import and export
https://www.npmjs.com/package/node-firestore-import-export
MIT License
392 stars 79 forks source link

firestore-import NodeJS Geopoint conflict #401

Open michael-martinez opened 4 years ago

michael-martinez commented 4 years ago

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__": {}
    }
    }
  2. 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.

michael-martinez commented 4 years ago

When exporting then importing, I get no problem but the export loses the Geopoint data type information (thus importing after leads to non Geopoint type being imported):

Exported:

{
  "sample_data": {
    "destinationCoordinates": {
        "_latitude": 48.830226,
        "_longitude": 2.370378
    },
    "__collections__": {}
  }
}