MongoRuntimeError: Connection pool closed

MongoRuntimeError: Connection pool closed

我看到我的 mongoose 池在它插入数据之前似乎关闭了,因为我在调用我的云集群中的 mongoose 数据库时收到此错误

MongoRuntimeError: Connection pool closed

但我正在等待所有电话?所以我不确定为什么会看到这个问题,也许这与我定义客户的方式有关?希望有人对此有一些提示或想法

export const storeData = async (data) =>{
    const uri = `mongodb+srv://plantmaster:${password}@cluster0.yey8l.mongodb.net/plantstore?retryWrites=true&w=majority`;
    const client = await MongoClient.connect(uri, {
        useNewUrlParser: true,
        useUnifiedTopology: true,
        serverApi: ServerApiVersion.v1
      });

        const newPLantData = { name: "Company Inc", address: "Highway 37" };
        await client.db("plantstore").collection("plantdata").insertOne(newPLantData, (err, res) =>{
            if(err) throw err;
            console.log(result)
        })
       
        await client.close();
};

我像这样在快速 post 路线上调用此函数

// store data
app.post('/store', async function (req, res) {
 await storeData(req.body);
  res.send('data was stored')
})

我遇到了同样的错误,但我通过在关闭连接前等待 1500 毫秒来修复它。

setTimeout(() => {client.close()}, 1500)