我有以下触发器,很难在父字段上进行递增。有什么建议吗?
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const fieldValue = admin.firestore.FieldValue;
admin.initializeApp();
exports.onTicketCreate = functions.firestore
.document('/contests/{contestId}/{tickets}/{ticketId}')
.onWrite((snapshot, context) => {
functions.firestore.document('contests/' + context.params.contestId).update({
points: fieldValue.increment(1)
});
});
错误
TypeError: Cannot read property 'increment' of undefined
at exports.onTicketCreate.functions.firestore.document.onWrite (/workspace/lib/index.js:27:48)
at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:132:23)
at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:330:28)
at process._tickCallback (internal/process/next_tick.js:68:7) 发布于 2020-06-28 05:42:45
老实说,我不确定为什么它不能工作,但我让它在下面的代码中工作
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
exports.waitReportCreatedJS = functions.firestore
.document('/contests/{contestId}/{tickets}/{ticketId}')
.onWrite((snapshot, context) => {
admin.firestore().doc('contests/' + context.params.contestId)
.update({ points: admin.firestore.FieldValue.increment(1) })
.then(() => console.log('this will succeed'))
.catch(() => 'obligatory catch');
});https://stackoverflow.com/questions/62615440
复制相似问题