21
21
import com .mongodb .DBObject ;
22
22
import com .mongodb .Mongo ;
23
23
import com .mongodb .MongoClient ;
24
+ import com .mongodb .MongoClientURI ;
25
+ import com .mongodb .ReadPreference ;
24
26
import com .mongodb .util .Util ;
25
27
26
28
import java .io .File ;
@@ -37,24 +39,24 @@ public class CLI {
37
39
* Dumps usage info to stdout
38
40
*/
39
41
private static void printUsage () {
40
- System .out .println ("Usage : [--bucket bucketname ] action" );
42
+ System .out .println ("Usage : [--db database ] action" );
41
43
System .out .println (" where action is one of:" );
42
44
System .out .println (" list : lists all files in the store" );
43
45
System .out .println (" put filename : puts the file filename into the store" );
44
46
System .out .println (" get filename1 filename2 : gets filename1 from store and sends to filename2" );
45
47
System .out .println (" md5 filename : does an md5 hash on a file in the db (for testing)" );
46
48
}
47
49
48
- private static String host = "127.0.0.1" ;
49
50
private static String db = "test" ;
50
-
51
+ private static String uri = "mongodb://127.0.0.1" ;
51
52
private static Mongo _mongo = null ;
52
53
53
54
@ SuppressWarnings ("deprecation" )
54
55
private static Mongo getMongo ()
55
56
throws Exception {
56
- if ( _mongo == null )
57
- _mongo = new MongoClient ( host );
57
+ if ( _mongo == null ) {
58
+ _mongo = new MongoClient (new MongoClientURI (uri ));
59
+ }
58
60
return _mongo ;
59
61
}
60
62
@@ -73,8 +75,6 @@ public static void main(String[] args) throws Exception {
73
75
return ;
74
76
}
75
77
76
- Mongo m = null ;
77
-
78
78
for ( int i =0 ; i <args .length ; i ++ ){
79
79
String s = args [i ];
80
80
@@ -85,7 +85,13 @@ public static void main(String[] args) throws Exception {
85
85
}
86
86
87
87
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 ];
89
95
i ++;
90
96
continue ;
91
97
}
0 commit comments