PackageCom.xinsight.server;Importjava.net.UnknownHostException;Importjava.util.ArrayList;Importjava.util.List;ImportCom.mongodb.BasicDBObject;ImportCom.mongodb.DB;Importcom.mongodb.DBCollection;ImportCom.mongodb.DBCursor;ImportCom.mongodb.DBObject;ImportCom.mongodb.Mongo;ImportCom.xinsight.Util.BeanUtil;ImportCom.xinsight.Util.InitMongodb;ImportCom.xinsight.Util.Manager;Importcom.xinsight.server.model.PhoneEntity;/*** Find the list collection in a column in MongoDB*/ Public classFindmongodbserver { Public Static voidMain (String args[]) {Try{Mongo mg=NewMongo ("localhost", 27017); DB DB= Mg.getdb ("admin"); if(Db.authenticate ("AA", "AA". ToCharArray ())) {db= Mg.getdb ("Dxtext"); Dbcollection DBC= Db.getcollection ("zq1"); Dbcursor u=Dbc.find (); while(U.hasnext ()) {String n= ""; Basicdbobject obj=(Basicdbobject) u.next (); ArrayList<BasicDBObject> list = (arraylist<basicdbobject>) obj.get ("L"); for(Basicdbobject basi:list) {n+ = Basi.getstring ("n") + "_" + basi.getstring ("T") + "#";//stitching the data in a list} n= n.substring (0, N.length ()-1); SYSTEM.OUT.PRINTLN (n); intsum = 0;//total number of calls receivedString strs[] = N.split ("#"); for(inti = 0;i < strs.length;i++){ intA = Integer.parseint (Strs[i].split ("_") [1]); Sum+=A; } System.out.println (Obj.get ("n") + "" + sum);//Total number of calls called by Caller IDSystem.out.println ("----------------------"); Thread.Sleep (1000); } } } Catch(unknownhostexception e) {e.printstacktrace (); } Catch(interruptedexception e) {e.printstacktrace (); } }}
java-viewing data in MongoDB (contains list collection)