javacript insert into MongoDB, how to change write concern

I want to test the insert rate with write concern = 0. But dont know where to change in js code.

db.testData.insert( 
        {"global_node_id": 1,
        "some_node_id": 1,
        "data": "data"})

Here is one line in js to insert. I didnt understand that where to put the {w:0}

Is it some where when I do connect to the database? or in the insert command?

I tried with following:

conn = new Mongo()
db = conn.getDB("myDatabase",{w:0});

No error pop up, but it does not speed up. So I guess this is not the way.

Assuming by "js code" you mean "in the mongo shell", as that is what your code implies, you specify unacknowledged write concern in insert operations like so:

> db.test.insert({a: 1}, {writeConcern: {w: 0}})
WriteResult({ })

Short version

db.testData.insert( { 'global_node_id': 1, 'some_node_id': 1, 'data': 'data' }, { writeConcern: {w:0} } )

Long version

I'm assuming (giving your code and the node.js tag) that you are actually using the NodeJS driver for MongoDB, not the mongo shell.

The syntax for insert is:

collection.insert(docs[[, options], callback])

(as can be seen in the docs).

So, you have an optional second argument that stands for the options. You can pass the write concern in the options as shown there.