(1)下载连接java 的驱动包mongo-2.10.1.jar 下载网址 https://github.com/mongodb/mongo-java-driver/downloads
(2)导入下载好的驱动包
(3)简单的使用demo
import java.net.UnknownHostException;
import com.mongodb.DB; import com.mongodb.Mongo;
public class SimpleTest {
/** * @param args * @throws UnknownHostException */
public static void main(String[] args) throws UnknownHostException {
// TODO Auto-generated method stub
//链接mongoDB 端口27017
Mongo mongo=new Mongo("127.0.0.1",27017);
//获取名为test的数据库对象
DB db=mongo.getDB("test");
//获取该库中的所有集合
for(String name:db.getCollectionNames()){
System.out.println("name:"+name);
} }
}