Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-390

GetLastError doesn't work with authentication

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.4
    • Affects Version/s: 1.3.1
    • Component/s: None
    • Labels:
      None

      Note: this bug only applies when calling GetLastError explicitly. Using SafeMode.True works fine with authentication.

      To reproduce:

      var server = MongoServer.Create("mongodb://username:password@localhost");
      var database = server["test"];
      var collection = database["test"];
      
      using (database.RequestStart())
      {
          collection.Insert(new BsonDocument("x", 1));
          var result = server.GetLastError();
      }
      

      Produces the following stack trace:

      System.InvalidOperationException: Connection requires credentials.
         at MongoDB.Driver.Internal.MongoConnection.CheckAuthentication(MongoDatabasedatabase) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 243
         at MongoDB.Driver.MongoServer.AcquireConnection(MongoDatabase database, Boolean slaveOk) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServer.cs:line 1126
         at MongoDB.Driver.MongoCursorEnumerator`1.AcquireConnection() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 210
         at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 223
         at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs:line 141
         at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
         at MongoDB.Driver.MongoCollection.FindOneAs[TDocument](IMongoQuery query) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 513
         at MongoDB.Driver.MongoCollection`1.FindOne(IMongoQuery query) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 1660
         at MongoDB.Driver.MongoDatabase.RunCommandAs(Type commandResultType, IMongoCommand command) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 875
         at MongoDB.Driver.MongoDatabase.RunCommandAs[TCommandResult](IMongoCommand command) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line 852
         at MongoDB.Driver.MongoServer.GetLastError() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoServer.cs:line 906
         at TestFree7051.Program.Main(String[] args) in c:\users\robert stam\documents\visual studio 2010\Projects\TestFree7051\Program.cs:line 23
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: