0

I have the following, & im using it to log in and do a query, so I get through db.authenticate, but when I do my query I get thrown:

MongoError: unauthorized data ns:data.data lock type:0 client:127.0.0.1] name: 'MongoError' }

As ridiculous as the code block below may seem with all the nesting, i guess thats javascript's only flaw.

Db.open(function(err, db) {     
    if(!err) {
    db.authenticate("admin", "1234", function(authdb, err) {

            if(!err) { //YAY I LOG IN!!!

              db.collection('data', function(err, collection) {
                collection.findOne({'id':'1'}, function(err, item) {
                    if(err) { //What?!? I AM logged in
                         db.close();
                         console.log(err);

                }
              }  );
            }  );
          }
        }  ); //Sad face
    }
});

How comes I can authenticate but I can't run the findOne query? If I try the same with the same user in the mongo shell it goes through.

Tarang
  • 75,157
  • 39
  • 215
  • 276
  • In the code above your db is called data and your collection is also called data? How exactly do you perform authentication and the same find in mongo shell? – Asya Kamsky Mar 02 '13 at 12:48

1 Answers1

3

Try swapping authdb and err:

// WRONG
db.authenticate("admin", "1234", function(authdb, err) { ... });
// RIGHT
db.authenticate("admin", "1234", function(err, authdb) { ... });
robertklep
  • 198,204
  • 35
  • 394
  • 381
  • Thank you! That did it, I decided to move to MongoConnect though, it seems to be far easier – Tarang Mar 02 '13 at 13:20