获取“eslint”-编译 firebase 云函数时出现解析错误
Getting `eslint' - parsing error, while compiling firebase cloud function
最近我开始做一个基于 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
我尝试了很多,但找不到解决此问题的线索。请求帮助解决。
我现在正在分享我在 MDN Web Doc 中找到的 await 文档。
要等待 Promise,请使用 await 运算符。在标准 JavaScript 代码中,它只能在异步函数中使用。
如果在函数定义前使用 async 关键字,则可以在函数内使用 await。当您等待 promise 结算时,该功能将以非阻塞方式停止。如果遵守诺言,您将获得价值。如果承诺失败,则抛出被拒绝的值。
最近我开始做一个基于 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
我尝试了很多,但找不到解决此问题的线索。请求帮助解决。
我现在正在分享我在 MDN Web Doc 中找到的 await 文档。
要等待 Promise,请使用 await 运算符。在标准 JavaScript 代码中,它只能在异步函数中使用。
如果在函数定义前使用 async 关键字,则可以在函数内使用 await。当您等待 promise 结算时,该功能将以非阻塞方式停止。如果遵守诺言,您将获得价值。如果承诺失败,则抛出被拒绝的值。