保存更新的异步方法值

时间:2020-09-15 18:13:25

标签: mean-stack

我正在做一个外部API调用以获取一些数据,我想将其保存到我的mongodb中。

var today = moment().format('dddd');
var menu = new Menu();
menu = await restaurant.days.forEach(async day => {
    if(day.dayOfWeek.toLowerCase() == today.toLowerCase()){
        return await day.meals.forEach(async meal =>{
            var menuMeal = new MenuMeal();
            const [price, description] = await Promise.all([getInfoFromSelector(meal.priceSelector, url), getInfoFromSelector(meal.mealSelector, url)]);
            menuMeal.price = price;
            menuMeal.description = description;
            menuMeal.type = meal.mealType;
            menu.menuMeals.push(menuMeal);
            return menu;
        })
    }
})
restaurant.menu = menu;
restaurant.save();

我认为我没有正确理解异步js方法。任何人都可以在这里向我指出正确的方向,这样我就不会一直都在被忽视。

0 个答案:

没有答案