Определения асинхронных функций в MongoDB (Atlas) Stitch отображает предупреждения в редакторе GUI.Включая пример кода, приведенный в справочнике по триггерам.
Найденный код здесь можно скопировать непосредственно в редактор функций Stitch и выдает предупреждения из-за ключевого слова 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 и должен ли я беспокоиться о показанных предупреждениях.