[JAVA-299] MongoUri does not work accoring to documentation Created: 18/Mar/11  Updated: 16/Nov/21  Resolved: 21/Apr/11

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 2.5
Fix Version/s: 2.6

Type: Bug Priority: Major - P3
Reporter: Ragnar Aas Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7, Spring 3, Java.



 Description   

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.



 Comments   
Comment by auto [ 21/Apr/11 ]

Author:

{u'login': u'rcugut', u'name': u'Radu Cugut', u'email': u'rcugut@gmail.com'}

Message: Bugfix: JAVA-299 - MongoURI does not parse URIs as specified in the documentation (http://www.mongodb.org/display/DOCS/Connections)
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/1cb8f5cb57dc8d457f0fe1b4ec061876c99c98c2

Comment by Radu Cugut [ 19/Apr/11 ]

Same problem with our code. Using 2.5.3. We hacked it to use the form user@pass:hostname. But recently, we took advantage of the fact this is an open-source project and fixed it in the code and pushed a maven artifact in our private repo

There is a pull-request on github that fixes this
https://github.com/mongodb/mongo-java-driver/pull/30

Generated at Thu Feb 08 08:51:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.