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.