Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firestore-import NodeJS Geopoint conflict #401

Open
michael-martinez opened this issue May 18, 2020 · 1 comment
Open

firestore-import NodeJS Geopoint conflict #401

michael-martinez opened this issue May 18, 2020 · 1 comment

Comments

@michael-martinez
Copy link

michael-martinez commented May 18, 2020

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
Copy link
Author

michael-martinez commented May 18, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant