Mehran
Mehran

Reputation: 16841

Setting MongoDB's write concern in shell / shell script

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]

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

mongo ./test.js

And here's the content of test.js file:

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() }
    ]);
}

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

Upvotes: 3

Views: 1784

Answers (1)

Oliver Wolf
Oliver Wolf

Reputation: 11

You can specify a write concern for each insert/update operation:

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

Upvotes: 1

Related Questions