gpt4 book ai didi

javascript - 在 mongodb shell javascript forEach 函数中写入关注

转载 作者:行者123 更新时间:2023-11-30 17:39:24 24 4
gpt4 key购买 nike

mongo shell 默认为安全写入,根据我的理解,这发生在每次回车结束时。如果你有这样的循环代码怎么办:

db.coll1.find().forEach(function(doc){
db.coll2.update({"blah": doc._id}, {$set: {"blahblah": doc.value}});
});

db.getLastError() 是在每次更新时发生,还是仅在最后一次更新的 for 循环结束时发生?还是在每个更新文档的 for 循环结束时同时发生?

最佳答案

shell 在交互模式下实际上有 w:1(安全写入),当在循环中运行时它不会调用 getLastError 直到结束。

作为引用,您实际上可以看到为 MongoDB Inc. 工作的@Asya 的评论。

the shell uses safe in that it called getLastError after every "command" (i.e. carriage return). If you are writing data, say, in a loop then GLE will only be called once at the end. Provide more details about how you plan to populate collection from the shell - maybe the right thing will already happen

Setting MongoDB's write concern in shell / shell script

关于javascript - 在 mongodb shell javascript forEach 函数中写入关注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21392418/

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