Database--mongodb-->java Articles

Source: Internet
Author: User
Tags data structures iterable mongoclient object object

Mongodbis a database based on distributed file storage. Written by the C + + language. Designed to provide scalable, high-performance data storage solutions for Web applications. Mongodbis a product between a relational database and a non-relational database, the most versatile of the non-relational databases, most like relational databases. The data structure he supports is very loose and is a JSON-like Bson format, so you can store more complex data types. MONGO's biggest feature is that his supported query language is very powerful, its syntax is a bit like object-oriented query language, almost can realize the most functions like relational database single table query, but also support the indexing of dataWhat is MongoDB?

MongoDB is written by the C + + language and is an open source database system based on distributed file storage.

In the case of high load, adding more nodes can guarantee the performance of the server.

MongoDB is designed to provide scalable, high-performance data storage solutions for Web applications.

MongoDB stores data as a document and data structures consist of key-value (key=>value) pairs. A MongoDB document is similar to a JSON object. Field values can contain other documents, arrays, and array of documents.

Key Features
    • MongoDB provides a document-oriented storage that is simple and easy to operate.
    • You can set the index of any property in the MongoDB record (for example: Firstname= "Sameer", address= "8 Gandhi Road") for faster sorting.
    • You can create data mirroring either locally or on the network, which makes MongoDB more extensible.
    • If the load increases (requiring more storage space and greater processing power), it can be distributed across other nodes in the computer network which is called a shard.
    • The MONGO supports rich query expressions. Query directives use a JSON-style tag to easily query objects and arrays embedded in the document.
    • MongoDb uses the update () command to implement a replacement of the completed document (data) or some specified data fields.
    • The map/reduce in MongoDB is primarily used for batch processing and aggregation of data.
    • Map and reduce. The map function calls emit (Key,value) to traverse all records in the collection, passing key and value to the reduce function for processing.
    • The map function and the reduce function are written in JavaScript and can be executed with the Db.runcommand or MapReduce command.
    • Gridfs is a built-in feature in MongoDB that can be used to store a large number of small files.
    • MongoDB allows you to execute scripts on the server, write a function in JavaScript, execute directly on the server, or store the definition of the function on the server, next time you call it directly.
    • MongoDB supports a variety of programming languages: ruby,python,java,c++,php,c# and many more languages.
    • MongoDB installation is simple.
Working with the MongoDB database in Java
    1. Installation and configuration of MongoDB under Windows
    2. Importing MongoDB jar Packages: Mongo-java-driver-3.2.2.jar
      • First create a folder, the jar package into which, generally named Lib;
      • Right-click the jar package that appears click Build path--> click Add to build path, so the jar package import is completed
    3. Also need to import the JSON jar package: Json-lib-2.4-jdk15.jar, as above, the main function is to parse the MONGODB data key value pair
Code Demo:
     Public Static voidMain (string[] args)throwsException {//TODO auto-generated Method StubMongoclient mclient=NewMongoclient ("localhost", 27017);//Connect MongoDB Database Local + port numberMongodatabase mdatabase=mclient.getdatabase ("Myta");//connecting to a databaseMongocollection<document> mcollection=mdatabase.getcollection ("MyDB");//get the data set under this database, like a tablefinditerable<document> iterable = Mcollection.find ();//set up a query to query all of the data setsMongocursor<document> Cursor=iterable.iterator ();//iterate over the data set and put it in the cursor     while(Cursor.hasnext ()) {//Traverse this cursorJsonobject jobject=NewJsonobject (Cursor.tostring ());//using JSON to parse the key value pairs of MongoDBObject object= jobject.getstring ("name");//get the key to the desired data, output the valueSystem.out.println (object); }     }

This requires your environment configuration is OK, pay more attention to the configuration of the environment and the import of the jar package, the code is not wrong

Personally think Studio 3T is a good visualization tool for MongoDB

Database--mongodb-->java Articles

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.