forked from mongodb/mongo-java-driver
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQuickTourAdmin.java
More file actions
50 lines (37 loc) · 1.13 KB
/
Copy pathQuickTourAdmin.java
File metadata and controls
50 lines (37 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.BasicDBObject;
public class QuickTourAdmin {
public static void main(String[] args) throws Exception {
/*
* connect to the local database server
*/
Mongo m = new Mongo();
/*
* Authenticate - optional
*/
// boolean auth = db.authenticate("foo", "bar");
for (String s : m.getDatabaseNames()) {
System.out.println(s);
}
/*
* get a db
*/
DB db = m.getDB("com_mongodb_MongoAdmin");
/*
* do an insert so that the db will really be created. Calling getDB() doesn't really take any
* action with the server
*/
db.getCollection("testcollection").insert(new BasicDBObject("i",1));
for (String s : m.getDatabaseNames()) {
System.out.println(s);
}
/*
* drop a database
*/
m.dropDatabase("com_mongodb_MongoAdmin");
for (String s : m.getDatabaseNames()) {
System.out.println(s);
}
}
}