@@ -403,11 +403,31 @@ public void init() {
403403 Properties props = getProperties ();
404404 String urls = props .getProperty ("mongodb.url" , "mongodb://localhost:27017" );
405405
406- database = props .getProperty ("mongodb.database" , "ycsb" );
407406 /* Credentials */
407+ database = props .getProperty ("mongodb.database" , "ycsb" );
408+
409+ // Retrieve username and password from properties, set to empty string if they are undefined
408410 String username = props .getProperty ("mongodb.username" , "" );
409411 String password = props .getProperty ("mongodb.password" , "" );
410412
413+ // If the URI contains an @, that means a username and password are specified here as well, so this will parse them out
414+ if (urls .contains ("@" )) {
415+ String uriCredentials = urls .substring (urls .indexOf ("//" ) + 2 , urls .indexOf ("@" ));
416+ String [] uriCredentialsList = uriCredentials .split (":" );
417+ String uriUsername = uriCredentialsList [0 ];
418+ String uriPassword = uriCredentialsList [1 ];
419+
420+ // If both the URI and properties have credentials defined, check that they are equivalent
421+ // If they are not, update credentials to those in the URI and log a warning
422+ if (props .keySet ().contains ("mongodb.username" ) && props .keySet ().contains ("mongodb.password" )){
423+ if (!uriUsername .equals (username ) || !uriPassword .equals (password )){
424+ System .out .println ("WARNING: Username/Password provided in the properties does not match what is present in the URI, defaulting to the URI" );
425+ }
426+ }
427+ username = uriUsername ;
428+ password = uriPassword ;
429+ }
430+
411431 // Set insert batchsize, default 1 - to be YCSB-original equivalent
412432 final String batchSizeString = props .getProperty ("batchsize" , "1" );
413433 BATCHSIZE = Integer .parseInt (batchSizeString );
0 commit comments