node-firestore-import-export icon indicating copy to clipboard operation
node-firestore-import-export copied to clipboard

firestore-import NodeJS Geopoint conflict

Open michael-martinez opened this issue 5 years ago • 1 comments

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.

michael-martinez avatar May 18 '20 14:05 michael-martinez

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

michael-martinez avatar May 18 '20 15:05 michael-martinez