我正在尝试在 MongoDB 的 shell 中填充一个集合。据我了解,使用轻松的 Write Concern
可以大大加快该过程。我说的是 the documentation关于 Write Concerns
是如何工作的,但它所谈论的只是它们是如何工作的,而不是如何设置它们(它说这是在驱动程序中设置的)。我看过不同驱动程序的文档以及它们是如何设置的,但我似乎无法找到 Write Concerns
是如何在 MongoDB 的 shell 本身中设置的!有谁知道如何从 shell 中设置它们?
[更新]
为了填充我的数据库,我使用了一个 .js
文件并将其提供给 mongo
命令,如下所示:
mongo ./test.js
test.js
文件的内容如下:
for (var i=0; i<1000000; i++) {
db.kingdom.insert([
{ "counter" : 0, "last_update" : new Date() }
, { "counter" : 0, "last_update" : new Date() }
...
, { "counter" : 0, "last_update" : new Date() }
]);
}
数据数组包含 100 个相同结构的对象。
最佳答案
您可以 specify a write concern for each insert/update operation :
db.blogs.insert({title: 'new blog post'}, {writeConcern: {j: true}})
关于mongodb - 在 shell/shell 脚本中设置 MongoDB 写关注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19065040/