Google Cloud Functions错误:“无法从Firestore值解码类型"
在React应用中使用Firestore,Im使用Google Cloud Functions进行测试以获取文档字段,然后使用该字段在Firestore中创建一个新字段.前几天我让它工作了,但现在却没有.
Using Firestore in a React app, Im testing out using Google Cloud Functions to grab a document field, and then create a new field in Firestore using that field. I had it working the other day and now it is not.
这是我在Google Cloud Function日志中得到的错误:
This is the error that Im getting in the Google Cloud Function log:
错误:无法从Firestore值中解码类型:{"stringValue":"sox"} 在DocumentSnapshot._decodeValue
Error: Cannot decode type from Firestore Value: {"stringValue":"sox"} at DocumentSnapshot._decodeValue
下面是我使用的代码.它与此处的代码非常相似: https://firebase.google .com/docs/firestore/extend-with-functions#writing_data
Below is the code I used. It is very similar to the code here: https://firebase.google.com/docs/firestore/extend-with-functions#writing_data
exports.createShowDoubleName = functions.firestore
.document('shows/{showId}')
.onUpdate((event) => {
const data = event.data.data();
const previousData = event.data.previous.data();
if (data.name == previousData.name) return;
var name = data.name;
var newname = name+"_"+name
return event.data.ref.set({
newname: newname
}, {merge: true});
});