We have a nodejs + mongodb application that has been running in production for several years, and in development on multiple machines. On just one developer's machine, I'm seeing the error
MongoError: collection already exists
Researching this error indicates that this will occur when trying to create an existing collection only if the collection is in strict mode. We don't invoke mongo's strict mode anywhere in our application, and we can only reproduce this error on one machine.
Code which 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 mongo's default strict: false
value? Is there a global configuration option that causes strict mode to be turned on? I would rather not modify the code to specify strict: false
for every collection just to enable a single developer. The developer is running mongo v3.2
You can disable 'strict' mode by 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 read more about this from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With