MongoNetworkError:首次连接时无法连接到服务器[localhost:27017][MongoNetworkError:与localhost的连接27:27017超时]

问题描述 投票:0回答:1

我正在尝试使用 mongoose 的 insertMany 创建一些文档,但在连接到 Mongo 主机时失败。

我的代码如下:

const { current, last } = getDates();
const currentData = await getProofsOfDeliveryData(current);
const lastData = await getProofsOfDeliveryData(last);
const data = [...currentData, ...lastData];
await ProofOfDeliveryProd.deleteMany();
await ProofOfDeliveryProd.insertMany(data);

我预计插入大约12k个文档

javascript mongodb mongoose
1个回答
0
投票

您可以在 insertMany() 中使用标志 limit

像这样:

await User.insertMany(users,{limit:10});

更多信息:https://mongoosejs.com/docs/api/model.html#Model.insertMany()

© www.soinside.com 2019 - 2024. All rights reserved.