时间:2021-07-01 10:21:17 帮助过:5人阅读
public class mongo { public static void main(String[] args) { // TODO Auto-generated method stub MongoClient mo = new MongoClient("127.0.0.1",27017); DB db = mo.getDB("wtdd"); DBCollection col = db.getCollection("wtdd"); DBObject o = new BasicDBObject("name","jim"); DBCursor cur = col.find(); for(DBObject obc:cur) { System.out.println(obc); } } //db.createCollection("wt", new DBObject()); }
连接数据库输出集合数据
查找固定的数据
public class mongo { public static void main(String[] args) { // TODO Auto-generated method stub MongoClient mo = new MongoClient("127.0.0.1",27017); DB db = mo.getDB("wtdd"); DBCollection col = db.getCollection("wtd"); DBObject o = new BasicDBObject("name","jim"); DBCursor lis = col.find(o); for(DBObject obj:lis) { System.out.println(obj); } }
}
mongoDB连接数据库
标签:sys rate highlight div 合数 client cli creat void