MongoDB Default in strict mode

We have a nodejs + mongodb application that has been in production for several years and in development on multiple machines. On one developer's machine, I see an error

MongoError: collection already exists 

An examination of this error indicates that this will happen when you try to create an existing collection only if the collection is in strict mode. We do not call mongo strict mode anywhere in our application, and we can only reproduce this error on one machine.

The code that causes this error is as follows:

 var mongo = require('mongodb'); mongo.MongoClient.connect(config.mongoConnectionString, {w:1}, function(err, db) { db.createCollection('accounts', function(err, collection) { // "err" here is the error message. }); }); 

Is there a way to override the mongo default strict: false value? Is there a global configuration option that enables strict mode? I would prefer not to change the code to specify strict: false for each collection to include only one developer. Developer launches mongo v3.2

+8
mongodb
source share
1 answer

You can disable the "strict" mode using this

 var mongo = require('mongodb'); mongo.MongoClient.connect(config.mongoConnectionString, {w:1}, function(err, db) { db.createCollection('accounts', {strict:false}, function(err, collection) { // "err" here is the error message. }); }); 

You can learn more about this from here.

+1
source share

All Articles