Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-10318

getLastError() always returns "getLastError command failed: need to login"

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.4, 2.2.5
    • Component/s: Internal Client
    • None
    • Environment:
      Debian Linux 7 x86_64, mongodb-10gen=2.2.5
    • Linux
    • Hide

      Steps to reproduce:

      1. Install Debian 7 x86_64 add the 10gen repo
      2. apt-get install mongodb-10gen=2.2.5
      3. Enable auth = true in /etc/mongodb.conf
      4. /etc/init.d/mongodb restart
      5. Create the test database:
        > use admin
        > db.addUser("admin", "admin")
        > use testdb
        > db.addUser("testuser", "testpass")
        
      6. Get the mongodb-src-r2.2.5.tar.gz tarball
      7. Compile only the client with the following command:
        scons --use-system-boost --release mongoclient
      8. Compile the following simple C++ test.cpp program:
        test.cpp
        #include <iostream>
        #include <string>
        #include <mongo/client/dbclient.h>
        
        using namespace std;
        
        int main() {
          mongo::DBClientConnection connection;
          string host = "localhost:27017";
          connection.connect(host);
        
          string error;
          connection.auth("testdb", "testuser", "testpass", error, true);
          cout << "Auth: " << error << endl;
        
          mongo::BSONObj obj = BSON("name" << "Dummy text");
        
          connection.insert("testdb.unittest", obj);
          error = connection.getLastError();
          cout << "insert getLastError(): " << error << endl;
        
          connection.query("testdb.unittest", BSON("name" << "Dummy text"));
          error = connection.getLastError();
          cout << "query getLastError(): " << error << endl;
        
          return 0;
        }
        
      9. g++ test.cpp -lmongoclient -lboost_filesystem -lboost_thread -lboost_system
      10. Run a.out

      Current result:

      $ ./a.out
      Auth: 
      insert getLastError(): getLastError command failed: need to login
      query getLastError(): getLastError command failed: need to login
      

      Expected result:

      $ ./a.out
      Auth: 
      insert getLastError(): 
      query getLastError():
      

      Some notes:

      • The {{ {"name": "Dummy text"}

        }} object will be actually inserted into the database each time when the program is run, so getLastError() should NOT return error.

      • Version 2.2.3 inclusive works fine.
      • Between version 2.2.3 and 2.2.4 there were changes in the authentication table implementation.
      • Versions 2.4.x seems to be fine as well.
      Show
      Steps to reproduce: Install Debian 7 x86_64 add the 10gen repo apt-get install mongodb-10gen=2.2.5 Enable auth = true in /etc/mongodb.conf /etc/init.d/mongodb restart Create the test database: > use admin > db.addUser("admin", "admin") > use testdb > db.addUser("testuser", "testpass") Get the mongodb-src-r2.2.5.tar.gz tarball Compile only the client with the following command: scons --use-system-boost --release mongoclient Compile the following simple C++ test.cpp program: test.cpp #include <iostream> #include <string> #include <mongo/client/dbclient.h> using namespace std; int main() { mongo::DBClientConnection connection; string host = "localhost:27017" ; connection.connect(host); string error; connection.auth( "testdb" , "testuser" , "testpass" , error, true ); cout << "Auth: " << error << endl; mongo::BSONObj obj = BSON( "name" << "Dummy text" ); connection.insert( "testdb.unittest" , obj); error = connection.getLastError(); cout << "insert getLastError(): " << error << endl; connection.query( "testdb.unittest" , BSON( "name" << "Dummy text" )); error = connection.getLastError(); cout << "query getLastError(): " << error << endl; return 0; } g++ test.cpp -lmongoclient -lboost_filesystem -lboost_thread -lboost_system Run a.out Current result: $ ./a.out Auth: insert getLastError(): getLastError command failed: need to login query getLastError(): getLastError command failed: need to login Expected result: $ ./a.out Auth: insert getLastError(): query getLastError(): Some notes: The {{ {"name": "Dummy text"} }} object will be actually inserted into the database each time when the program is run, so getLastError() should NOT return error. Version 2.2.3 inclusive works fine. Between version 2.2.3 and 2.2.4 there were changes in the authentication table implementation. Versions 2.4.x seems to be fine as well.

      Starting from the version 2.2.4 of the Mongo Client C++ driver calling the getLastError() after a successful operation always results in "getLastError command failed: need to login" error when authentication is enabled.

            Assignee:
            spencer@mongodb.com Spencer Brody (Inactive)
            Reporter:
            bszente Balint Szente
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: