新异步函数中的异步函数

async function inside new async function

我需要使用 mongoose 从 Mongo db 获取数据,然后使用 node-fetch 发送一些请求。 所以我在下面创建了异步函数

async function mainThree() {

    await ProvinceList.find({}).then((data) => {

        data.forEach((provience) => {
            console.log(provience.id)
            let response = await fetch(`https://xxxx.com/api/getSubAddressList?addressId=${provience.id}`, {
                "headers": {
                    "accept": "application/json, text/plain, */*",
                    "accept-language": "en-US,en;q=0.9,si;q=0.8",
                    "cache-control": "no-cache",

                },
                "referrer": "https://www.xxxx.com/",
                "referrerPolicy": "strict-origin-when-cross-origin",
                "body": null,
                "method": "GET",
                "mode": "cors"
            });

            let datalist = await response.json();


            CityList.insertMany(datalist.module);

        });


    });



}

但是当我 运行ning 代码时,我得到

**SyntaxError: await is only valid in async function**

我需要知道如何 运行 异步函数在异步函数中

在这种情况下,您在传递给 forEach 的函数内部使用了 await。您需要使该函数异步。

data.forEach(async (province) => ...