MongoDB API-Simple Sample Applet

Source: Internet
Author: User

Reading group: Beginners who are not familiar with MongoDB.

Plus: As this ID is used for the first time with MongoDB, please also indicate if there is an understanding deviation.


1 Some concepts:

A MongoDB service can build multiple databases, each database can have more than one table, in general, the name of our database table is called

Collection, each Collection can hold multiple documents, each document is stored in Bson (binary) in the form of a hard disk,

So you can store more complex forms in the hard disk, so you can store more complex objects, which are stored in the form of documents. You can give

Any document or batch of documents is added or deleted without affecting other documents. This is the Schema-free, and the general key-

The value database is as follows, which is also the main advantage of the document type database,


Unlike the general Key-value database, it stores structure information in value, so you can read, write, and count some domains like a relational database. MONGO's biggest feature is that the query language he supports is very powerful, and its syntax is a bit like an object-oriented query language that almost implements most of the functionality of a relational database single-table query, and also supports indexing of data. MONGO can also solve the query efficiency of massive data, according to official documents, when the amount of data reached more than 50GB data, MONGO database access speed is more than MySQL10 times.



BSON is the abbreviation for Binay JSON, BSON has the following three features:

1 Light weight

2 boast platform

3 Efficient

Namespaces: MongoDB Village Coarse Bson objects to collections, this series of database names, and Colelctions are

Become a namespace.


A small program:

package test;import java.net.unknownhostexception;import java.util.arraylist;import  java.util.list;import org.slf4j.logger;import org.slf4j.loggerfactory;import  com.esotericsoftware.minlog.log;import com.mixbox.mongodb.impl.mongodbutil;import  com.mongodb.basicdbobject;import com.mongodb.db;import com.mongodb.dbcollection;import  Com.mongodb.mongo;import com.mongodb.serveraddress;public class testipchecker {public  static final logger log = loggerfactory.getlogger (MongoDBUtil.class);//  MongoDB address static serveraddress address = null;//  cluster Address set static list< Serveraddress> list = new arraylist<serveraddress> ();// mongo Object static  mongo m = null;//  Database Object static db db = null;static {try { Address = new serveraddress ("192.168.50.25",  30000);}  catch  (unknownhostexception e)  {// TODO Auto-generated catch  Blocke.printstacktrace ();} List.add (address), M = new mongo (list);d b = m.getdb ("Shoptest");} Public static void main (String[] args)  throws Exception {MongoDBUtil  Mongoutil = new mongodbutil (); Int needinc = mongoutil.checkhasip ("192.168.50.165 ");// for  (int i = 0; i < 100; i++)  {//  Insertintomongo ("192.168.50.165");//// }isneed (needinc);} Public static void p (Object o)  {system.err.println (o.tostring ());} Public static void isneed (int needinc)  {if  (needinc == 1)  {p (" Need to increase, there is no "inside the Library");}  else {p ("Does not need, the library has");}} Public static void insertintomongo (String dimensionip)  {dbcollection collection  = db.getcollection ("Dimensionipbase");//  gets the table'sHandle//  Package Query condition basicdbobject basicdbobject = null; Basicdbobject newdbobject = new basicdbobject (); Newdbobject.put ("Dimensionip",  DIMENSIONIP); Collection.insert (Newdbobject);}}


Basicdbobject fact also corresponds to the Document object. Use Basicdbobject to manage.

MongoDB API-Simple Sample Applet

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.