【发布时间】:2020-06-08 15:13:30
【问题描述】:
我正在尝试使用云功能,这样当在集合“RecruiterJobs”中创建文档时,会触发云功能并更新集合“CollegeCode”的文档中的值,并根据条件单个文档或所有文档收集文件将被更新, 这是我的云函数的 index.js 部分
const functions = require('firebase-functions');
const admin= require('firebase-admin');
exports.TPOjobcount = functions.firestore
.document('Recruiter/{JobId}')
.onCreate((snap, context) => {
const newValue = snap.data();
const colleges = newValue.Colleges
if (colleges === 'All'){
const docRef = admin.firestore().collection('CollegeCode')
docRef.get().then(snapshot=>{
snapshot.forEach(doc=>{
docRef.ref.set({
OffCampusJobs:firebase.firestore.FieldValue.increment(1),
JobRecruiter: firebase.firestore.FieldValue.arrayUnion(newValue.CompanyName)
},{merge:true}).catch(() => null)
})
}).catch(() => null)
}
当我尝试运行 firebase deploy --only 函数时,它给出了错误
19:39 error Each then() should return a value or throw promise/always-return
21:29 warning Avoid nesting promises promise/no-nesting
30:62 error Each then() should return a value or throw promise/always-return
32:17 warning Avoid nesting promises promise/no-nesting
【问题讨论】:
标签: javascript node.js firebase google-cloud-firestore google-cloud-functions