首先,下载mongoDB对Java支持的驱动包
驱动包下载下面建立一个JavaProject工程,导入下载下来的驱动包。即可在Java中使用mongoDB.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public class MongoDb {
public static void main(String[] args) throws UnknownHostException {
MongoClient mg = new MongoClient();
DB db = mg.getDB("CRUD");
DBCollection users = db.getCollection("test");
DBCursor cur = users.find();
while (cur.hasNext()) {
System.out.println(cur.next());
}
System.out.println(cur.count());
System.out.println(cur.getCursorId());
System.out.println(JSON.serialize(cur));
}
}
使用Java操作MongoDB
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!
- Post link: http://izheyi.com/2014/12/20/使用Java操作MongoDB/
- Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.