MongoDB Introduction and Installation

Source: Internet
Author: User
Tags mongodb server

about MongoDB


1. Introduction

MongoDB is a database based on Distributed file storage . Written by the C + + language. Designed to provide scalable, high-performance data storage solutions for Web applications.

MongoDB is a product between a relational database and a non-relational database, and is the most versatile and most like relational database in a non-relational database. 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 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.

2. Features
It is characterized by high performance, easy to deploy, easy to use , and easy to store data.

The main features are:
* For collection storage, easy to store object type data.
* Free mode.
* Support Dynamic Query.
* Full index support, including internal objects.
* Support Query.
* Supports replication and recovery.
* Use efficient binary data storage, including large objects (such as video, etc.).
* Automatically handles fragmentation to support scalability at the cloud level.
* Support multiple languages such as ruby,python,java,c++,php,c#.
* File storage format is Bson (an extension of JSON).
* Can be accessed via the Internet.

3. Principle of Use
The so-called "set-oriented" (collection-oriented), meaning that data is grouped in a dataset, is called a collection (Collection). Each collection has a unique identifying name in the database and can contain an unlimited number of documents. The concept of a collection is similar to a table in a relational database (RDBMS), unlike it does not need to define any schema (schema).

Mode Freedom (schema-free) means that for files stored in a MongoDB database, we do not need to know any of its structure definitions. If necessary, you can store files of different structures in the same database.

The documents stored in the collection are stored in the form of key-value pairs. The key is used to uniquely identify a document as a string type, whereas a value can be a variety of complex file types. We call this storage form Bson (Binary serialized Document Format).

4. Practical Application
The MongoDB server can run on Linux, Windows or iOS platforms, supports 32-bit and 64-bit applications, and the default port is 27017. It is recommended to run on a 64-bit platform because MongoDB supports a maximum file size of 2GB when running in 32-bit mode.


Bson Getting Started


1. Concept

BSON (binary serialized document format) is a binary form of a class JSON storage format, called binary JSON, which, like JSON, supports embedded document objects and array objects. However, Bson has some data types that JSON does not have, such as date and bindata types.

Bson can be used as a form of storage for network data exchange, which is somewhat similar to Google's protocol Buffer, but Bson is a kind of schema-less storage, it has the advantage of high flexibility, but its disadvantage is that space utilization is not ideal.

Bson has three characteristics: light weight, ergodic, high efficiency.

{"Hello": "World"} This is an example of a bson, where "Hello" is the key name, which is generally the CString type, and the byte representation is cstring::= (byte*) "/x00", where * represents 0 or more byte bytes,/ The x00 represents a terminator, and the following "World" is the value, which is typically of type string,double,array,binarydata.

2, the use of the situation
MongoDB uses the Bson structure to store data and network data exchange. This format is translated into the document, because Bson is schema-free, so the corresponding document in MongoDB also has this feature, and here, one document can be understood as a record in a relational database (record), It's just that the document here is a little more varied, as document can be nested.

One of the important reasons for MongoDB to Bson as its storage structure is its ergodic nature.

3. Example
3.1 Bson of a document says

{    title:"MongoDB",    last_editor:"192.168.1.122",    last_modified:New Date ("27/06/2011"),    body:"MongoDB Introduction",    categories:["Database", " NoSQL "," BSON "],    revieved:false  }

This is a simple bson structure in which each element is composed of key/value pairs.

3.2 An example of nesting

{    name:"Lemo", age    :"A",address:{city        :"Suzhou",        Country: "China",        code:215000 },    scores:[        {"name": "中文版", "grade:3.0}        ",  ]}

This is an example of a relatively complex point, including an array of address objects and fractional objects, where nested document objects and document object data are used to represent individual students ' information, a nested document structure that is more complex to use a relational database.


Installing MongoDB under Windows7


1. Download

Address: Http://www.mongodb.org/downloads (32-bit or 64-bit choice).
I downloaded: mongodb-win32-x86_64-2.4.5.zip

2. Decompression
Put the mongodb-win32-x86_64-2.4.5.zip in one place and unzip it. I put it in the D:\dev directory.
The path after decompression is D:\dev\mongodb-win32-x86_64-2.4.5

3. Installation Preparation
The default data directory for MongoDB is: C:\data\db. If you do not use the default directory, you need to add the--dbpath parameter after the Mongod.exe command.
Create a Data Catalog. I created a D:\dev\mongodb-win32-x86_64-2.4.5\data\db.
Create the log directory and its files. I created D:\dev\mongodb-win32-x86_64-2.4.5\log and D:\dev\mongodb-win32-x86_64-2.4.5\log\log.txt.

4. Start MongoDB
Open cmd window (cmd.exe), enter D:\dev\mongodb-win32-x86_64-2.4.5\bin, execute Mongod.exe command, see.
Mongod.exe--logpath=d:\dev\mongodb-win32-x86_64-2.4.5\log\log.txt--dbpath=d:\dev\mongodb-win32-x86_64-2.4.5\ Data\db

The--logpath parameter is the path to the set log file.
The--dbpath parameter is the set path for the database file.
All parameter options for the Mongod.exe command can be viewed through Mongod.exe--help.

5. Install as a service
Open the Windows CMD window with administrator privileges and enter the D:\dev\mongodb-win32-x86_64-2.4.5\bin directory.
Mongod.exe--install--logpath=d:\dev\mongodb-win32-x86_64-2.4.5\log\log.txt--dbpath=d:\dev\mongodb-win32-x86_ 64-2.4.5\data\db
The--install parameter is set to install as a server

Once set as a service, you can start or stop MongoDB in the form of a service by using the cmd ( Windows CMD window with Administrator privileges open ) window.
net start MongoDB start MongoDB Service
net stop MongoDB start MongoDB service

6. Enter the shell environment Interface
Enter the Sheelmongodb, enter the D:\dev\mongodb-win32-x86_64-2.4.5\bin directory in the cmd window, input mongo.exe, you can enter the shell environment interface.

MongoDB Introduction and Installation

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.