MongoDB (ii)

Source: Internet
Author: User
Tags mongoclient

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)

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.