2121import com .mongodb .DBObject ;
2222import com .mongodb .Mongo ;
2323import com .mongodb .MongoClient ;
24+ import com .mongodb .MongoClientURI ;
25+ import com .mongodb .ReadPreference ;
2426import com .mongodb .util .Util ;
2527
2628import java .io .File ;
@@ -37,24 +39,24 @@ public class CLI {
3739 * Dumps usage info to stdout
3840 */
3941 private static void printUsage () {
40- System .out .println ("Usage : [--bucket bucketname ] action" );
42+ System .out .println ("Usage : [--db database ] action" );
4143 System .out .println (" where action is one of:" );
4244 System .out .println (" list : lists all files in the store" );
4345 System .out .println (" put filename : puts the file filename into the store" );
4446 System .out .println (" get filename1 filename2 : gets filename1 from store and sends to filename2" );
4547 System .out .println (" md5 filename : does an md5 hash on a file in the db (for testing)" );
4648 }
4749
48- private static String host = "127.0.0.1" ;
4950 private static String db = "test" ;
50-
51+ private static String uri = "mongodb://127.0.0.1" ;
5152 private static Mongo _mongo = null ;
5253
5354 @ SuppressWarnings ("deprecation" )
5455 private static Mongo getMongo ()
5556 throws Exception {
56- if ( _mongo == null )
57- _mongo = new MongoClient ( host );
57+ if ( _mongo == null ) {
58+ _mongo = new MongoClient (new MongoClientURI (uri ));
59+ }
5860 return _mongo ;
5961 }
6062
@@ -73,8 +75,6 @@ public static void main(String[] args) throws Exception {
7375 return ;
7476 }
7577
76- Mongo m = null ;
77-
7878 for ( int i =0 ; i <args .length ; i ++ ){
7979 String s = args [i ];
8080
@@ -85,7 +85,13 @@ public static void main(String[] args) throws Exception {
8585 }
8686
8787 if ( s .equals ( "--host" ) ){
88- host = args [i +1 ];
88+ uri = "mongodb://" + args [i +1 ];
89+ i ++;
90+ continue ;
91+ }
92+
93+ if ( s .equals ( "--uri" ) ){
94+ uri = args [i +1 ];
8995 i ++;
9096 continue ;
9197 }
0 commit comments