在shell/shell脚本中设置MongoDB的写关注 [英] Setting MongoDB's write concern in shell / shell script

查看:54
本文介绍了在shell/shell脚本中设置MongoDB的写关注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 MongoDB 的外壳中填充一个集合.据我了解,使用轻松的Write Concern可以大大加快该过程.我说的是文档关于Write Concerns的工作方式,但它所讨论的只是它们的工作方式,而不是如何设置它们(它说这是在驱动程序中设置的).而且我看过不同驱动程序的文档以及它们的设置方式,但我似乎找不到在 MongoDB 的外壳本身中设置Write Concerns的方法!有谁知道如何从外壳设置它们?

I'm trying to populate a collection within MongoDB's shell. As I understand, using a relaxed Write Concern can speed up the process a lot. I'm talking about the documentation on how Write Concerns work but all it talks about is how they work and not how to set them (it says this is set in the driver). And I've seen documents for different drivers and how it is set in them but I can't seem to find how Write Concerns are set in MongoDB's shell itself! Does anyone know how to set them from the shell?

[UPDATE]

要填充我的数据库,我使用了.js文件,并将其提供给mongo命令,如下所示:

To populate my database I used a .js file and gave it to mongo command like this:

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个具有相同结构的对象.

The data array goes for 100 objects of the same structure.

推荐答案

您可以为每个插入/更新操作:

db.blogs.insert({title:'new blog post'},{writeConcern:{j:true}})

db.blogs.insert({title: 'new blog post'}, {writeConcern: {j: true}})

这篇关于在shell/shell脚本中设置MongoDB的写关注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆