Java operations on MongoDBNoSQL Databases

Source: Internet
Author: User
Tags mongodb client mongodb latest version
I. Introduction MongoDB is a high-performance, open-source, non-relational (NoSQL) Document-type database that can be run directly with unzip without installation, it can be used in many scenarios to replace traditional relational databases or key-value storage methods. Developed Using C ++, Mongo provides the following features: * Set-oriented storage: Suitable for storage

I. Introduction MongoDB is a high-performance, open-source, non-relational (NoSQL) Document-type database that can be run directly with unzip without installation, it can be used in many scenarios to replace traditional relational databases or key/value storage methods. Mongo uses C ++ to enable the following features: * Set-oriented storage: Suitable for storage

I. Introduction
MongoDB is"Green"High-performance, open-source, non-relational (NoSQL) document-based databases can be run without installation and direct decompression (unzip, it can be used in many scenarios to replace traditional relational databases or key/value storage methods. Mongo uses C ++ to enable the following functions:
* Set-oriented storage: Suitable for storing objects and JSON data.
* Dynamic query: Mongo supports multiple Query expressions. Query commands use JSON tags to easily query embedded objects and arrays in a document.
* Complete indexing support: Includes embedded object and array of documents. The Query Optimizer of Mongo analyzes the query expression and generates an efficient query plan.
* Query monitoring: Mongo provides a monitoring tool to analyze the performance of database operations.
* Replication and automatic failover: The Mongo Database supports data replication between servers and master-slave mode and mutual replication between servers. The primary objective of replication is to provide redundancy and automatic failover.
* Efficient traditional storage: supports binary data and large objects (such as photos or images ).
* Automatic sharding to support cloud-level Scalability (in the early alpha stage): the automatic sharding function supports horizontal database clusters and allows you to dynamically add additional machines.

Ii. Scenario
MongoDB's main goal is to build a bridge between key/value storage and traditional RDBMS systems, combining the advantages of both. Mongo is suitable for the following scenarios:
* Website data: Mongo is ideal for real-time insertion, update, and query, as well as the replication and high scalability required for real-time website data storage.
* Cache: because of its high performance, Mongo is also suitable for serving as a cache layer for information infrastructure. After the system is restarted, the persistent cache layer established by Mongo can avoid data source overload at the lower layer.
* Large-sized and low-value data: traditional relational databases may be expensive to store some data. Previously, programmers often choose traditional files for storage.
* High scalability: Mongo is ideal for databases consisting of dozens or hundreds of servers. The Mongo roadmap contains built-in support for the MapReduce engine.
* The BSON data format of Mongo is very suitable for storing and querying object and JSON data.

Iii. Preparation
1. Download MongoDB latest version list http://www.mongodb.org/display/DOCS/Downloads,
Download the http://github.com/mongodb/mongo-java-driver/downloads of the required Jar driver package.

2. decompress the mongodb-linux-i686-1.2.4.tgz file you just downloaded.

3. Copy the decompressed mongodb directory to the directory you specified.

4. Create a data file directory mkdir-p/var/lib/mongodb/

5. Run the Mongodb service "./mongod-dbpath/var/lib/mongodb/-logpath/var/log/mongodb. log"
Specifies the directory where data files are stored, and specifies the directory where data log files are input.Thu Mar 25 22:18:52 waiting for connections on port 27017Indicates that the service is successfully started.

Iv. Example (CRUD/Java)
1. Create a connection
Mongo db = new Mongo (host, port );
DBCollection coll = db. getDB (dbName). getCollection ("testCollection ");
System. out. println (coll );

2. perform the operation
DBCollection coll = getConnection (host, port, dbName );
DBObject myDoc = coll. findOne ();
System. out. println (myDoc );

For the complete sample code, click here to download (Ref)

5. scalability
MongoDB can also adopt Sharding policies. Data routing is the role of mongos in MongoDB ,:

Related Articles:
Getting started with mongodb
Architecture Design of Large video website Justin. TV
Mailinator architecture of a large JavaMail website (Linux + Tomcat + Java)
MongoDB Cluster
MongoDB client tools constantly collect ing (figure)


-End-

Original article address: I would like to thank the original author for using MongoDB NoSQL databases in Java.

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.