The traditional relational database is usually composed of three hierarchical concepts of database, table and record.
MongoDB is made up of three levels (database), collection (collection), Document object (documents).
MongoDB is for tables in relational databases, but there is no concept of columns, rows, and relationships in the collection, which embodies the nature of pattern freedom.
Java Code Connection query:
try {
Mongoclientoptions.builder build = new Mongoclientoptions.builder ();
Maximum number of connections to data 50
Build.connectionsperhost (50);
If all current connection are in use, there can be 50 threads queued for each connection
Build.threadsallowedtoblockforconnectionmultiplier (50);
Build.connecttimeout (1*60*1000);
Build.maxwaittime (2*60*1000);
Mongoclientoptions options = Build.build ();
Mongoclient mongoclient = new Mongoclient ("192.168.8.22", options);//connection address or localhost
Mongodatabase mgdb = mongoclient.getdatabase ("SPT");
System.out.println ("Connect to Database successfully!");
System.out.println ("Mongodatabase inof is:" +mgdb.getname ());
Mongocollection<document> collection = Mgdb.getcollection ("SPT");
finditerable<document> f = collection.find (Filters.eq ("id", "29e01a0f23e9461ca871e10661292895"));
Document d = F.first ();
Sugartestcommentbean sugarcomment = Jsonutils.fromjson (D.tojson (), sugartestcommentbean.class);
list<commentbean> commentlist = sugarcomment.getcomments ();
pagefinder<commentbean> Pagefinder = new pagefinder<commentbean> ();
Pagefinder.setdata (commentlist);
Modelmap.put ("Pagefinder", Pagefinder);
Mongoclient.close ();
} catch (Exception e) {
System.err.println (E.getclass (). GetName () + ":" + e.getmessage ());
}
MongoDB (ii)