1

I would like to set the write concern for an entire collection using the mongojs library.

This is what I think the code might look like

var mongojs = require('mongojs');
var db = mongojs('testdb');
var test = db.collection('test', {writeConcern: {w: 0}}); 

but I'm having a very difficult time testing if this's working or not since no matter what I pass no errors get thrown and nothing changes in the responses.

How can I change the default write concern for an entire collection or is it not even possible?

Loourr
  • 4,995
  • 10
  • 44
  • 68

1 Answers1

0

Turns out it can be specified in the connection string as documented here.

var db = mongojs('username:password@example.com/mydb?w=0', ['mycollection'])

Where w=0 is setting the write concern.

Loourr
  • 4,995
  • 10
  • 44
  • 68
  • It's odd. The nodejs mongo driver seems to only allow one to set the write concern on a per-operation basis. Meanwhile, a collection allows you to "get" the writeConcern property. A db does too. A db allows you to set the readConcern property (but only allows a get of writeConcern). Go figure. http://mongodb.github.io/node-mongodb-native/2.0/api/Db.html and http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html seem relevant. – Armadillo Jim Nov 10 '15 at 05:23