Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-299

MongoUri does not work accoring to documentation

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6
    • Affects Version/s: 2.5
    • Component/s: API
    • Labels:
      None
    • Environment:
      Windows 7, Spring 3, Java.

      I tried using the documented format for the URI :

      But got an "String index out of range" error in line 69 of MongoUri-class. Upon examining the code, I see the problem :

      if ( serverPart.indexOf( "@" ) > 0 )

      { int idx = serverPart.indexOf( "@" ); _username = serverPart.substring( 0 , idx ); serverPart = serverPart.substring( idx + 1 ); idx = serverPart.indexOf( ":" ); Line 69 : _password = serverPart.substring( 0 , idx ).toCharArray(); serverPart = serverPart.substring( idx + 1 ); }

      In the above, I am guessing the problem is two-fold.

      1) In retrieving the password, you are using "serverPart" instead of "_username" . But now the "serverPart" parameter holds everything behind "@".
      2) No check that idx>0. Which may be right, since this would after all be a fault on the developer (maybe, depending upon the usage).

      In the above code, using "serverPart" instead of "_username", the correct usage would be :

      mongodb://<username>@<password>:<server>/<db-name>.<db-collection>

      But I am guessing this is wrong. I have tried the above, and see that this does not throw an exception.

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            ragnaraas Ragnar Aas
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: