MongoDB Getting Started tutorial (i)

Source: Internet
Author: User
Tags create directory mongodb commands mongodb version mongodb support


About MongoDB


Mongdb is a high-performance, open-source, modeless, document-based NoSQL database.


Main Features:


1. File storage format Bson (an extension of JSON)
2. Mode freedom
Data format is not constrained by the structure of the table
3. Support Dynamic Query
4. Full index support
5. Support Replication (its master-slave replication) and recovery
6. Use efficient binary data storage, including large objects
7. Automatically process fragmentation to support scaling at the cloud level.
8. Support for Java, Ruby, Python, C + +, PHP and many other languages
9. Internal JavaScript support


The advantages of MongoDB


1. Fast query speed
2. High concurrency. Can reach 20,000 concurrent.
3. High capacity. The amount of data that supports 10TB meaning
MongoDB Usage Scenarios
1. Website data
2. Caching
3. Large-size, low-value data
4. High-stretch scene
5. For objects and JSON data storage


MongoDB restrictions


1. Data greater than 2.5G is not supported on 32-bit operating systems
2. Single File size limit 16M
3. Highly transactional systems
4. Traditional Business intelligence applications


MongoDB differs from other databases




MongoDB Installation


Here, the main explanation is win under Install, about Linux under installation, then add on.
Download URL: Official website (https://www.mongodb.org/downloads/#production)
The Win32 is used here.

The author downloads The old long time only then finishes, estimated is the personal network speed question,





After installation, the following directories are found in the installation directory


Configure path PATH [OPTIONAL]


The path path is configured so that you can enter MONGODB commands directly from the command prompt, without having to switch to the MongoDB bin directory each time. Right-click on [My Computer], select [Properties]=>[advanced system Settings]=>[advanced]=>[environment variable settings]=> system variables [path] Modify, add MongoDB Bin directory, I add directory is ' C:\Program Files\mongodb\server\3.2\bin '
The procedure is as follows:


Start the MONGDB service side


Refer to the official website: https://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/#install-mongodb-community-edition
Start Mongdb steps as follows


Setting up the MONGDB execution environment


The official quote is as follows:
Set up the MongoDB environment
1.MongoDB requires a data directory to store all data. MongoDB ' s default data directory path is \data\db. Create This folder using the following commands from a Command Prompt:
MD \data\db
MongoDB needs to specify a directory to store the data. Under win at the command prompt, you can use the MD command to create a directory. Here, I'll create a data directory and a log directory, which will be used to hold the database and log. Spit a notch, feel win under Create directory really does not have Linux under the convenience.

The directory under this directory is now created as follows


Start MongoDB (for server side)


The official quote is as follows:
To start MongoDB, run Mongod.exe. For example, from the Command Prompt:
C:\mongodb\bin\mongod.exe
This starts the main MongoDB database process. The waiting for connections message in the console output indicates, the Mongod.exe process is running successfully.
Is that we started MongoDB through Mongod.exe, started the MongoDB master data process, if there is a message waiting to connect, it implies that the Mongod.exe process is running successfully.
Okay, now we're starting up.
The start command is as follows:
mongod.exe --dbpath="C:\Program Files\MongoDB\Server\data" --logpath="C:\Program Files\MongoDB\Server\log\mongodb.log" --port=27017
If you do not configure the path directory of MongoDB, you need to switch to the bin directory of MongoDB or use C:\Program Files\mongodb\server\3.2\bin\mongod.exe to execute.
Parse: DBPath Specify data storage directory, can be specified by itself
LOGPATH Specifies the log path, which can be specified by itself
PORT Specifies the port number, the default is 27017



Now that you have the following error

In other words, the 32-bit system does not turn on logging by default, use –journal to turn it on.
But when I entered the C:\Program files\mongodb\server\log directory, I found a log with the following contents:


 
 
016-04-28T21:42:47.003+0800 I CONTROL  [main] Hotfix KB2731284 or later update is not installed, will zero-out data files
2016-04-28T21:42:47.071+0800 I CONTROL  [initandlisten] MongoDB starting : pid=17916 port=27017 dbpath=C:\Program Files\MongoDB\Server\data 32-bit host=YEGZT8JOIIU2LKY
2016-04-28T21:42:47.072+0800 I CONTROL  [initandlisten] targetMinOS: Windows Vista/Windows Server 2008
2016-04-28T21:42:47.072+0800 I CONTROL  [initandlisten] db version v3.2.5
2016-04-28T21:42:47.072+0800 I CONTROL  [initandlisten] git version: 34e65e5383f7ea1726332cb175b73077ec4a1b02
2016-04-28T21:42:47.072+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2016-04-28T21:42:47.073+0800 I CONTROL  [initandlisten] modules: none
2016-04-28T21:42:47.073+0800 I CONTROL  [initandlisten] build environment:
2016-04-28T21:42:47.073+0800 I CONTROL  [initandlisten]     distarch: i386
2016-04-28T21:42:47.073+0800 I CONTROL  [initandlisten]     target_arch: i386
2016-04-28T21:42:47.073+0800 I CONTROL  [initandlisten] options: { net: { port: 27017 }, storage: { dbPath: "C:\Program Files\MongoDB\Server\data" }, systemLog: { destination: "file", path: "C:\Program Files\MongoDB\Server\log\mongodb.log" } }
2016-04-28T21:42:47.090+0800 I STORAGE  [initandlisten] exception in initAndListen: 28663 Cannot start server. The default storage engine ‘wiredTiger‘ is not available with this build of mongod. Please specify a different storage engine explicitly, e.g. --storageEngine=mmapv1., terminating
2016-04-28T21:42:47.090+0800 I CONTROL  [initandlisten] dbexit:  rc: 100


This log record, the command prompt is not the same as the prompt, ah, how to do? Because the command prompt is prompted because the log does not open due to errors, and the log says the engine is not appropriate. Only one try first. I do not add the log, execute the following command
mongod.exe --dbpath="C:\Program Files\MongoDB\Server\data" --port=27017

With this hint, it seems to be OK this time that the default storage engine is not supported. Had to change an engine. Execute the following command:


mongod.exe --dbpath="C:\Program Files\MongoDB\Server\data"  --logpath="C:\Program Files\MongoDB\Server\log\mongodb.log" -storageEngine="mmapv1" --port=27017  --journal


The results of the implementation are as follows:

I've been waiting for a connection, and I'm looking at some log logs

It seems to be starting up. Of course you can also enter http://localhost:27017 in the browser if the following interface appears, the code is installed successfully.


Connect to MongoDB (for clients)


The official quote is as follows:
Connect to MongoDB.?



To connect to MongoDB through the Mongo.exe shell, open another Command Prompt.



C:\mongodb\bin\mongo.exe
If you want to develop applications using. NET, see the documentation of C # and MongoDB for more information.



To connect to MongoDB, you need to open another Command prompt window to establish a connection via Mongo.exe. If you want to use the. NET development applications, you need to look at C # documentation and other MongoDB manuals for more information.



To be blunt, the client connects MongoDB via Mongo.exe. In fact, the direct input MONGO is the same, of course, I have some warning message here, can not be ignored for the time being.



Client connection MongoDB is as follows (the MongoDB inside can also be replaced with Mongo.exe)


Common commands


1.db.help ()
View command Prompt

2.db
View the name of the database in which it is currently located

3.use command
The Use+ database name represents a switchover or database creation. And the only difference between the use in MySQL, when the database does not exist, MongoDB can create a database.

4.show DBS
Show the database, you need to note that show DBS, only show the library with data, no data library, is not displayed. In the DQS database, there is no data at the beginning, so it is not displayed, and when I insert a database, show DBS displays it.

5.db.dropdatabase ()
Deletes the current data.
Before deleting

The current library does not change after the delete operation is performed.

After deletion, the database file is not there.

6.db.stats ()
View the status of the current data

7.db.version ()
View MongoDB version
8.db.getmongo ()
View the IP of the currently connected machine

9.mongoDB support for JavaScript
Because MongoDB supports JavaScript, you can enter the JS code directly at the command prompt. Such as



MongoDB Getting Started tutorial (i)


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.