java-viewing data in MongoDB (contains list collection)

Source: Internet
Author: User

 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.