【问题标题】:Getting `eslint' - parsing error, while compiling firebase cloud function获取`eslint' - 解析错误,同时编译firebase云功能
【发布时间】: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


【解决方案1】:

我现在分享的是我在 MDN Web Doc 中找到了 await 文档。

要等待 Promise,请使用 await 运算符。在标准 JavaScript 代码中,它只能在异步函数中使用。

如果在函数定义之前使用 async 关键字,则可以在函数中使用 await。当您等待 promise 完成时,该函数会以非阻塞方式停止。如果遵守诺言,您将获得价值。如果 promise 失败,则抛出被拒绝的值。

【讨论】:

    猜你喜欢
    • 2021-05-14
    • 2018-08-03
    • 2021-10-26
    • 2021-09-25
    • 2018-11-17
    • 2021-01-25
    • 2021-12-01
    • 2018-05-15
    相关资源
    最近更新 更多