-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchapter.nosql.mongodb.xml
More file actions
69 lines (56 loc) · 1.21 KB
/
chapter.nosql.mongodb.xml
File metadata and controls
69 lines (56 loc) · 1.21 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?xml version="1.0" encoding="UTF-8"?>
<chapter id="nosql">
<title>NoSQL</title>
<section>
<title>MongoDB</title>
<section>
<title>pom.xml</title>
<screen>
<![CDATA[
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.2.2</version>
</dependency>
]]>
</screen>
</section>
<section>
<title>插入操作</title>
<screen>
<![CDATA[
package cn.netkiller.controller;
import java.net.UnknownHostException;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoClient;
public final class Tracker {
public Tracker() {
}
public static void main(String[] args) {
MongoClient mongo = null;
try {
mongo = new MongoClient("192.168.4.1", 27017);
DB db = mongo.getDB("finance");
DBCollection table = db.getCollection("tracker");
BasicDBObject document = new BasicDBObject();
document.put("test", "helloworld");
table.insert(document);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
]]>
</screen>
</section>
<section>
<title>读取操作</title>
<screen>
<![CDATA[
]]>
</screen>
</section>
</section>
</chapter>