【发布时间】:2022-01-01 07:03:53
【问题描述】:
最近我开始研究一个基于 Firebase 云功能和 Firestore 数据库的项目。我正在编写一个云函数触发函数,它将在正在创建的新文档上查询“集合组”。
云功能代码文件如下:
exports.findDealsOnBuy = functions.firestore
.document('businessmen/{businessmenId}/buy/{buyId}')
.onCreate((snapshot, context) => {
const businessmenId = context.params.businessmenId;
const buyId = context.params.buyId;
const buy = snapshot.data();
functions.logger.info('businessmenId : ', businessmenId, ' buyId : ', buyId, ' buy : ', buy );
const sellGrpRef = admin.firestore().collectionGroup('sell');
const querySnapshot = await sellGrpRef.whereEqualTo('goodsName', '==', buy.getGoodsName())
.whereEqualTo('goodsLocation', '==', buy.getGoodsLocation())
.whereEqualTo('status', '==', 1)
.whereEqualTo('status', '==', 5)
.whereLessThanOrEqualTo('bestPrice', '<=', buy.getBestPrice())
.orderBy('bestPrice', 'desc')
.get();
if (querySnapshot.empty) {
console.log('No matching documents.');
return;
}
querySnapshot.forEach((doc) => {
console.log(doc.id, ' => ', doc.data());
});
});
但是在编译时我被抛出以下错误
> C:\Users\Suman\Kamakshi\Ganesh\Burrabazar\Cloudfunctions\functions\index.js
> 31:31 error Parsing error: Unexpected token sellGrpRef
我尝试了很多,但我找不到如何解决这个问题的线索。请求帮助解决。
【问题讨论】:
-
你只能在
async函数中使用await。
标签: javascript node.js firebase google-cloud-platform google-cloud-functions