9.6 MongoDB One

Source: Internet
Author: User
Tags failover mongodb server mongodb version

Directory:ASP. NET MVC enterprise-class actual directory9.6.1 MongoDB Introduction

MongoDB is a high-performance, open-source, modeless document-based database that is a popular one in the current NoSQL database. It can be used in many scenarios to replace the traditional relational database or key/value storage methods.

The traditional relational database is usually composed of three hierarchical concepts of database, table, record, and MongoDB is made up of database, collection (collection), Three levels of document objects. 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.

Features: high performance, easy to deploy, easy to use, easy to store data.

The main features are:

    • For collection storage, easy to store data for object types.
    • Mode of freedom.
    • Supports dynamic queries.
    • Supports full indexes, including internal objects.
    • Support Queries.
    • Supports replication and recovery.
    • Use efficient binary data storage, including large objects such as video.
    • Automatically process fragmentation to support scalability at the cloud level
    • Drivers for Python,php,ruby,java,c,c#,javascript,perl and C + + languages are supported, and drivers for Erlang and. NET platforms are also available in the community.
    • The file storage format is Bson (an extension of JSON).
    • can be accessed over the network.

 function :

    • Collection-oriented storage: suitable for storing objects and data in JSON form.
    • Dynamic query: MONGO supports rich query expressions. Query directives use a JSON-style tag to easily query objects and arrays embedded in the document.
    • Full index support: Includes embedded objects and arrays in the document. The query optimizer of MONGO parses the query expression and generates an efficient query plan.
    • Query monitoring: MONGO contains a monitoring tool to analyze the performance of database operations.
    • Replication and automatic failover: The MONGO database supports data replication between servers, supporting master-slave mode and inter-server replication. The primary goal of replication is to provide redundancy and automatic failover.
    • Efficient traditional storage: supports binary data and large objects (such as photos or pictures)
    • Auto-sharding to support cloud-scale scalability: Automatic sharding supports a level of database clustering, adding additional machines dynamically.

  applicable occasions :

    • Website data: MONGO is ideal for real-time inserts, updates and queries, as well as the replication and high scalability required for real-time data storage on the site.
    • Caching: Because of its high performance, MONGO is also suitable as a caching layer for the information infrastructure. After the system restarts, the persistent cache layer built by MONGO can avoid overloading the underlying data sources.
    • Large, low-value data: Storing some data in a traditional relational database can be expensive, and many times programmers often choose traditional files for storage.
    • Highly scalable scenario: The MONGO is ideal for databases made up of dozens of or hundreds of servers. Built-in support for the MapReduce engine is already included in the roadmap for MONGO.
    • Storage for objects and JSON data: The MONGO Bson data format is ideal for storing and querying in a document format.
9.6.2 Download Installation and configuration

1. Download the MongoDB installation package

Official Latest Version: Https://www.mongodb.com/download-center

Other versions: Https://www.mongodb.org/dl/win32/x86_64-2008plus-ssl,

Note: Although the latest version is 3.2.6, but the author tried 10 of the remaining MongoDB visualizer connection 3.2.6 version, the use of the problem, so I use the lower version of the 3.0.7. This also tells us an experience: in the selection of technology, do not pursue the latest, but should choose to meet the requirements and run very stable. Because of the latest technology, not only the relevant information is less, but also not through the actual validation of the project. The study cost is very high, the risk is big.

Of course, here, if you do not need to use the Visual client tool, there is no problem with the latest MongoDB version of the operation.

The author downloads the version 9-51 shown.

Figure 9-51

2. installing MongoDB under Windows

After the installation package is downloaded, MongoDB is installed in the directory C:\Program Files\mongodb by default.

View the C:\Program Files\mongodb\server\3.0\bin directory, as shown in 9-52.

Figure 9-52

The Mongod.exe is used to connect to the MONGO database server, which is the server side.

Mongo.exe is used to start the MongoDB shell, which is the client.

Other files:

Mongodump.exe: Logical Backup tool.

Mongorestore.exe: Logical Recovery Tool.

Mongoexport.exe: Data export tool.

Mongoimport.exe: Data import Tool.

(1) Configuring the MONGODB environment

In the new Data folder under Directory D:\WorkSpace\mongodb, the Data folder will be the root folder in which to store the information.

(2) Run cmd as Administrator. Perform the following 2 cmd commands, respectively:

CD \program Files\mongodb\server\3.0--dbpath D:\WorkSpace\mongodb\data

Note: The-dbpath parameter value in the last line of commands is the new folder we created in the first step. This folder must be established prior to opening the service, otherwise it will error, because MongoDB does not create this folder by itself.

When the command executes successfully, you will see the following.

C:\WINDOWS\SYSTEM32>CD \program Files\mongodb\server\3.0\binc:\program files\mongodb\server\3.0\bin>mongod.exe--DBPath D:\WorkSpace\mongodb\data .- .-04t00:xx:00.153+0800I JOURNAL [Initandlisten] JOURNAL dir=D:\WorkSpace\mongodb\data\journal .- .-04t00:xx:00.155+0800I JOURNAL [initandlisten] recover:no JOURNAL files present, no recovery needed .- .-04t00:xx:00.224+0800I JOURNAL [durability] durability thread started .- .-04t00:xx:00.224+0800I JOURNAL [JOURNAL writer] JOURNAL writer thread started .- .-04t00:xx:00.323+0800I CONTROL [Initandlisten] MongoDB starting:pid=4392port=27017Dbpath=d:\workspace\mongodb\data --bit host=desktop-v7cfic3 .- .-04t00:xx:00.324+0800I CONTROL [Initandlisten] Targetminos:windows7/windows Server -R2 .- .-04t00:xx:00.324+0800I CONTROL [Initandlisten] DB version v3.0.7 .- .-04t00:xx:00.324+0800I CONTROL [initandlisten] git version:6ce7cbe8c6b899552dadd907604559806aa2e9bd .- .-04t00:xx:00.324+0800I CONTROL [Initandlisten] Build info:windows sys.getwindowsversion (major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') boost_lib_version=1_49 .- .-04t00:xx:00.324+0800I CONTROL [Initandlisten] Allocator:tcmalloc .- .-04t00:xx:00.324+0800I CONTROL [Initandlisten] options: {storage: {dbPath:"D:\WorkSpace\mongodb\data" } } .- .-04t00:xx:00.326+0800I INDEX [Initandlisten] AllocatingNewns file D:\WorkSpace\mongodb\data\local.ns, filling with zeroes ... .- .-04t00:xx:00.586+0800I STORAGE [Fileallocator] AllocatingNewDataFile D:\WorkSpace\mongodb\data\local.0, filling with zeroes ... .- .-04t00:xx:00.589+0800I STORAGE [fileallocator] Creating directory D:\WorkSpace\mongodb\data\_tmp .- .-04t00:xx:00.597+0800I STORAGE [Fileallocator] done allocating datafile D:\WorkSpace\mongodb\data\local.0, SIZE:64MB, took0.004secs .- .-04t00:xx:00.623+0800I NETWORK [Initandlisten] Waiting forConnections on port27017

(3) In the browser input: http://localhost:27017/, you can see the following prompt:

It looks like you is trying to access MongoDB over HTTP on the native driver port.

Indicates that the MONGODB database service has successfully started.

(4) To see the D:\WorkSpace\mongodb\data folder again, you will find many more files under the data directory. As shown in 9-53.

Figure 9-53

Each time using the cmd command to open the MongoDB server and the client is very troublesome, we can completely make his service to service, set up the boot, and then the client can download the visual client management tools on-line. Here I'll show each of them as batch commands and services.

Mongodb Service Side

(1 ) made into batches

Create a new text file Mongodb_server.txt, and enter the following text:

" cd/d C:\Program files\mongodb\server\3.0\bin&&mongod--dbpath D:\WorkSpace\mongodb\data "

Then modify the file suffix name to bat, and the final file full name is Mongodb_server.bat.

(2 ) made Windows Service

Installation Services: Create a new text file Mongodb_server_ Installer.txt, enter the following text, and then save as a. bat file.

" cd/d C:\Program files\mongodb\server\3.0\bin&&mongod--install--servicename mongodb-servicedisplayname MongoDB--logpath D:\WorkSpace\mongodb\log\MongoDB.Log  --dbpath D:\WorkSpace\mongodb\dataEcho Service MongoDB installation succeeded ... echo is stopping the service ... net start Mongodbecho Press any key to exit ... pause start service: net start MongoDB

Run Mongodb_server_ installer.bat as Administrator.

Uninstall Service: Create a new text file Mongodb_server_ UnInstaller.txt, enter the following text, and then save as a. bat file.

Echo is stopping the service ... net stop Mongodbecho is removing the service ... sc delete Mongodbecho Press any key to exit ... pause

Run Mongodb_server_ uninstaller.bat as Administrator.

Mongodb Client

Create a new text file Mongodb_client.txt, and enter the following text:

" cd/d C:\Program Files\mongodb\server\3.0\bin&&mongo "

Then modify the file suffix name to bat, and the final file full name is Mongodb_client.bat.

You can simply double-click the batch command to run when you need to start it later.

9.6 MongoDB One

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.