MongDBjava连接简单实例
默认情况.MongoDB服务./mongod 开启服务是只能本机访问 ,需要开放所有ip或者指定连接的ip地址./bin/mongod -bind_ip_all
public static void main(String[] args) { try { MongoClient mongoClient = new MongoClient("192.168.25.128", 27017); MongoDatabase database = mongoClient.getDatabase("test"); System.out.println("连接成功"); MongoCollection<Document> ldw = database.getCollection("ldw"); Document first = ldw.find().first(); System.out.println(first.toJson()); } catch (Exception e) { System.out.println(e.getClass().getName() + ":" + e.getMessage()); } }