MONGODB NODE.JS DRIVER 2.1

104 views
Skip to first unread message

Roland Bole

unread,
Apr 19, 2016, 10:28:05 AM4/19/16
to mongodb-user
Hi, I have some problems with the new driver 2.1.
the same settings/application works well under 2.0.48.

I use an mongodb-server 3.0.3 with authentication. 

my start connection seems to work
2016-04-19T16:03:57.744+0200 I ACCESS   [conn1] Successfully authenticated as principal xxx1
2016-04-19T16:03:57.865+0200 I ACCESS   [conn2] Successfully authenticated as principal xxx2

and also some queries works as expected, but after some queries/commands I got the following error:

Unauthorized not authorized on xxx2 to execute command { update: xxx

OR


assertion 13 not authorized for query on


I would appreciate help, thanks.







 

Kevin Adistambha

unread,
Apr 29, 2016, 12:00:04 AM4/29/16
to mongodb-user

Hi Roland,

2016-04-19T16:03:57.865+0200 I ACCESS [conn2] Successfully authenticated as principal xxx2

Unauthorized not authorized on xxx2 to execute command { update: xxx

This sequence of message means that the user successfully authenticated to the server, but seems to lack authorization to perform the operation. I cannot seem to reproduce your issue by using MongoDB 3.0.3 and node.js driver versions 2.0.48 and 2.1.18.

I created a user named user with readWrite access to the test database:

> use admin
> db.system.users.find({user:"user"})
{
  "_id": "test.user",
  "user": "user",
  "db": "test",
  "credentials": {
    "SCRAM-SHA-1": {
      "iterationCount": 10000,
      "salt": "UY7iL204+Gl8PlxfZe3t/g==",
      "storedKey": "s2dgGPJ1ozsr/BQVltT7xvTxLFA=",
      "serverKey": "ilWGxBehJf89czrWeseQbenOH10="
    }
  },
  "roles": [
    {
      "role": "readWrite",
      "db": "test"
    }
  ]
}

and was able to successfully insert into a collection in the test database:

var MongoClient = require('mongodb').MongoClient;
var url = 'mongodb://localhost:27017/test';
MongoClient.connect(url, function(err, db) {
  assert.equal(null, err);
  console.log('Connected to server.');
  db.authenticate('user', 'password', function(err, res) {
    assert.equal(null, err);
    console.log('Authentication successful.');
    db.collection('test').insert({hello:'world'}, function(err, res) {
      assert.equal(null, err);
      console.log('Insert successful.');
      db.close();
    })
  })
});

Could you please double check if the user has the proper authorization to perform the required operation, and if anything has changed in your application code other than upgrading to the more recent node.js driver? If you are still having issues, it will be helpful to provide:

  • the output of db.system.users.find({user:<the relevant user>})
  • the operation you need to perform that fails authorization

Also, you might want to consider upgrading to the latest in the 3.0.x series, which currently is 3.0.11 for bugfixes and improvements.

Best regards,
Kevin

Roland Bole

unread,
Apr 29, 2016, 3:12:47 AM4/29/16
to mongodb-user
@Kevin
thanks for your response.

I will give you more information about how we use the driver. 

In my application I use the following process when my node application starts. I need connections to more than one databases so in the first step I create a connection to every database and store this reference for further use, if all connections are ready my application is ready to use.
auth: function(dbName){
  var deferred = q.defer();
  var DbServerRef = DbServer.db(dbName);
  var dbConfig = Config.getConfigItem(dbName);
  DbServerRef.authenticate(dbConfig.user, dbConfig.pwd, 
    function(err, result) {
     if(err)console.log(err);
     //console.log(DbServerRef);
     DbConns[DbServerRef.s.databaseName] = DbServerRef;
     console.log('Auth DB: '+DbServerRef.s.databaseName+' - OK');
     deferred.resolve(true);
    });

    return deferred.promise;
}

later in the application

if one request belongs to DB A than I grab the right reference from A and execute my query.
getDatabase: function(dbName){
DbReference = DbConns[dbName];
  return DbReference;
},

And here is the problem. Some requests are still working and at some time, the reported error happens, for my randomly. In this scenario I use also the same database.

This process works fine, i mean perfect, in 2.0.48. We use this for 6 months without any problem.

Christian Kvalheim

unread,
May 4, 2016, 8:46:52 AM5/4/16
to mongodb-user
Hi Roland can you repo using a minimal script and provide instructions and then open a jira.mongodb.com NODE ticket for me to track. Meanwhile the best workaround is using a separate MongoClient client connection for each database.

Roland Bole

unread,
May 4, 2016, 9:20:41 AM5/4/16
to mongodb-user
Hi,
ok, but i need some time for preparation.

Christian Kvalheim

unread,
May 4, 2016, 9:46:37 AM5/4/16
to mongodb-user
Hi there is no hurry I'm strapped for time for the next 10 days due to travel and other work related things

Soorya Prakash

unread,
Oct 1, 2016, 5:06:46 AM10/1/16
to mongodb-user
I am facing the same issue.Can anyone tell how to resolve this problem?

Kevin Adistambha

unread,
Oct 11, 2016, 1:08:09 AM10/11/16
to mongodb-user

Hi Soorya,

I am facing the same issue.Can anyone tell how to resolve this problem?

Could you please open a new thread with your issue, along with:

  • Your MongoDB and your Node.js driver versions
  • A small script that reproduces the issue
  • What have you tried so far, and what are the error messages you are seeing

Please note that the original thread is about Node.js driver version 2.1, and the current version of the driver is 2.2.10. If you’re having this issue with driver version 2.0, it might be worth checking if your issue is resolved with the new driver.

Best regards,
Kevin

Soorya Prakash

unread,
Oct 28, 2016, 3:36:09 AM10/28/16
to mongodb-user
I was updated the mongodb node driver to 2.2.4 and using same implementation.I still got the same problem.But I used alternative like " separate MongoClient client connection for each database" which worked as expected..

Thanks
Soorya
Reply all
Reply to author
Forward
0 new messages