【发布时间】:2019-05-22 00:47:07
【问题描述】:
MongoDB (Atlas) Stitch 上的异步函数定义在 GUI 编辑器上显示警告。包括触发器参考中提供的示例代码。
找到的代码 here 可以直接复制到缝合功能编辑器并由于 async 关键字而产生警告。
文档中的示例代码。
exports = async function (changeEvent) {
// Destructure out fields from the change stream event object
const { updateDescription, fullDocument } = changeEvent;
// Check if the shippingLocation field was updated
const updatedFields = Object.keys(updateDescription.updatedFields);
const isNewLocation = updatedFields.some(field =>
field.match(/shippingLocation/)
);
// If the location changed, text the customer the updated location.
if (isNewLocation) {
const { customerId, shippingLocation } = fullDocument;
const twilio = context.services.get("myTwilioService");
const mongodb = context.services.get("mongodb-atlas");
const customers = mongodb.db("store").collection("customers");
const { location } = shippingLocation.pop();
const customer = await customers.findOne({ _id: customer_id })
twilio.send({
to: customer.phoneNumber,
from: context.values.get("ourPhoneNumber"),
body: `Your order has moved! The new location is ${location}.`
});
}
};
我想知道 Stitch 是否支持 async/await 范式以及我是否应该关注显示的警告。
【问题讨论】:
-
警告实际上说的是什么?毕竟它只是一个警告......
-
大多数只是说缺少分号。经过反复试验,我发现
async关键字后面的分号使它停止显示,但当然这似乎是它的 linter 搞砸了。
标签: javascript mongodb async-await mongodb-stitch