首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Firestore增量未定义?

Firestore增量未定义?
EN

Stack Overflow用户
提问于 2020-06-28 04:52:18
回答 1查看 254关注 0票数 0

我有以下触发器,很难在父字段上进行递增。有什么建议吗?

代码语言:javascript
复制
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)
    });
  });

错误

代码语言:javascript
复制
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) 
EN

回答 1

Stack Overflow用户

发布于 2020-06-28 05:42:45

老实说,我不确定为什么它不能工作,但我让它在下面的代码中工作

代码语言:javascript
复制
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');
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62615440

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档