gpt4 book ai didi

mongodb - 使用 for 循环插入文档时出错

转载 作者:可可西里 更新时间:2023-11-01 10:48:48 26 4
gpt4 key购买 nike

当我尝试将一些文档添加到集合中时,4 次中正好有 1 次出现错误。

for (var i = 0; i < 50; i=i+1){
db.SampleOrder.insert(
{
"SampleId": NumberInt(i),
"PuckId": NumberInt(i)
});
}

错误: Picture of the Error

有人知道为什么这行不通吗?我使用 Robomongo Robo 3T 1.1.1。

最佳答案

你可以使用 insertMany 而不是 insert 来插入多个文档

喜欢:

var docs = [];
for (var i = 0; i < 50; i=i+1){
docs.push({
"SampleId": NumberInt(i),
"PuckId": NumberInt(i)
});
}
db.SampleOrder.insertMany(docs);

关于mongodb - 使用 for 循环插入文档时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45954706/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com