我正在尝试使用 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个文档
您可以在 insertMany() 中使用标志 limit:
像这样:
await User.insertMany(users,{limit:10});
更多信息:https://mongoosejs.com/docs/api/model.html#Model.insertMany()