I\'m calling a Firebase callable function, and returning the promise as specifed by Firebase, but I get this error:
Unhandled error RangeError: Maximum call stack si
The problem is similar to the one described here. You're returning a complex object generated by the Firebase API called a DocumentSnapshot. A snapshot it not itself raw JSON data to return to the client, and it contains circular references to other objects. Cloud Functions is stuck trying to serialize all of these objects. Instead, just return the raw JavaScript object of the data at the location of interest by calling val() on the snapshot:
return database
.ref('/products/' + product)
.orderByKey()
.endAt(ts)
.limitToLast(1)
.once('value') // once() returns a promise containing a snapshost
.then(snapshot => {
return snapshot.val() // this is the raw JS object
})
You generally don't use both the returned promise and the callback in the same call. It's easier to just use the promise.