First, i'd like to say that a lot of my code is probably horrible so my apologies. My .ts and .js experience is not at a point where I feel super comfortable (hence why I can't solve this). So i'm trying to get document content from one document to another. Currently doing it via snapshots though i'm sure there's faster and better ways. My code is below.
The error happens when I try to set the second collection (redacted2)'s document to the snapshot data. As you can tell from the console logs, I know that the snapshot.data() has the valuable information I need formatted exactly the way I want it to be. I'm assuming this is similar to having a guard statement in swift where I can check the value for null and assign it to a given type (but I could be wrong here).
db.collection("Redacted").doc(context.params.sensors).get()
.then(function(querySnapshot){
console.log("Query Snapshot is is isssss: ", querySnapshot)
console.log("Query Snapshot querySnapshot.data: ", querySnapshot.data)
console.log("Query Snapshot querySnapshot.data(): ", querySnapshot.data())
console.log("Query Snapshot querySnapshot.ref: ", querySnapshot.ref)
console.log("Query Snapshot querySnapshot.get: ", querySnapshot.get)
return querySnapshot
}).then(function(querySnapshotData) {
console.log("ayoooooo blooooddd", querySnapshotData)
db.collection("Redacted2").doc(context.params.sensors).set(querySnapshotData.data())
.then((alertResponse1: any) => {
console.log("Successfully updated firestore: ", alertResponse1)
})
.catch ((alertError1: any) => {
console.log("Successfully updated firestore but with error: ", alertError1)
})
})
.catch(function(error) {
console.log("query snapshot error: ", error)
});