importjava.net.UnknownHostException;importcom.mongodb.BasicDBObject;importcom.mongodb.DB;importcom.mongodb.DBCollection;importcom.mongodb.DBCursor;importcom.mongodb.DBObject;importcom.mongodb.Mongo;publicclassHelloMongoDB{privatestaticMongomg;privatestaticDBdb;privatestaticDBCollectioncol;publicstaticvoidmain(String[]args)throwsUnknownHostException{HelloMongoDBhello=newHelloMongoDB();if(mg==null){mg=newMongo("127.0.0.1",27017);}if(db==null){db=mg.getDB("Studing");}if(col==null){col=db.getCollection("test");}hello.InsertDocument(col);}publicvoidInsertDocument(DBCollectioncol){for(inti=0;i<10;i++){BasicDBObjectdocu=newBasicDBObject();docu.put("type","super");docu.put("price",i+10);col.insert(docu);}for(inti=0;i<10;i++){BasicDBObjectdocu=newBasicDBObject();docu.put("type","tang");docu.put("price",i+10);col.insert(docu);}}}
慕慕森
MM们
相关分类