PackageCom.xinsight.server;Importjava.net.UnknownHostException;ImportJava.util.HashMap;ImportCom.mongodb.BasicDBObject;ImportCom.mongodb.DB;Importcom.mongodb.DBCollection;ImportCom.mongodb.DBCursor;ImportCom.mongodb.Mongo;/*** Find all data in a column in MongoDB that contains a map collection*/ Public classFindmongodbmap {Private StaticMongo mg; Private StaticDB DB; Private Static intnum = 0; Public Static voidMain (String args[]) {Try{mg=NewMongo ("localhost", 27017); DB= Mg.getdb ("admin"); BooleanAuth = db.authenticate ("AA", "AA". ToCharArray ()); if(!auth) {System.err.println ("Link MongoDB failed"); }Else{db= Mg.getdb ("zq1"); Dbcollection Collection= Db.getcollection ("zq1"); Dbcursor u=Collection.find (); while(U.hasnext ()) {num++; Basicdbobject Basi=(Basicdbobject) u.next (); HashMap Map= (HASHMAP) basi.get ("M"); if(num% 100 = = 0) {System.err.println ("--------------------------------------------------------------------"); Thread.Sleep (3000); } System.out.println (Basi.get ("V1") + "" "+ Basi.get (" v2 ") +" "+basi.get (" v3 ") +" +basi.get ("v4") + "+ map.get (" time ") +" "+ ma P.get ("sex") + "" + map.get ("age") + "" + map.get ("name"))); } System.out.println ("Total found:" + num + "bar data"); } } Catch(unknownhostexception e) {e.printstacktrace (); } Catch(interruptedexception e) {e.printstacktrace (); } }}
java-viewing data in MongoDB (including the map collection)