3

I have a project where I am adding data from a POS system to firebase. I have been adding the JSON returned from an API call to the POS to the Firebase realtime database without issue but not want to use the Cloud firestore.

I have a very crude node script for testing this however when trying to add a document I receive the following error

UnhandledPromiseRejectionWarning: FirebaseError: Function DocumentReference.set() called with invalid data. Data must be an object, but it was: a custom object

The below is an example of the JSON I am trying to create a document out of

https://www.jasonbase.com/things/qp03.json

This is the JS I have that should write the json to a new document

const db = firebase.firestore();
  const merchantId = data.merchant_id;
  const docId = data.id;

  db.settings({
    timestampsInSnapshots: true
  });

  db.collection(merchantId)
    .doc(docId)
    .set(data)
    .then(function(docRef) {
      console.log("Document written with ID: ", docRef);
    })
    .catch(function(error) {
      console.error("Error adding document: ", error);
    });

What I don't get is that is I pass this JSON through this website and use the output as the data the document creation succeeds.

I have searched high and low for this issue and cannot figure it out.

chinds
  • 1,761
  • 4
  • 28
  • 54
  • Possible duplicate of [Function DocumentReference.set() called with invalid data. Unsupported field value: a custom Budget object](https://stackoverflow.com/questions/48156234/function-documentreference-set-called-with-invalid-data-unsupported-field-val) – Jake Lee Dec 12 '18 at 18:47
  • Hi, have had a look at that already and the solution suggested there does not work for me, I think it is different as that user is creating custom Objects as a class – chinds Dec 12 '18 at 19:33

0 Answers0