[MongoDB] Get used to Mysql, try MongoDB (install, download and use)
blog description
The information involved in the article comes from the Internet and personal summary, which is intended to summarize personal learning and experience. If there is any infringement, please contact me to delete it, thank you!
Introduction to MongoDB
MongoDB is written in C++ and is an open source database system based on distributed file storage.
In the case of high load, adding more nodes can ensure server performance.
MongoDB stores data as a document, and the data structure consists of key-value (key=>value) pairs. MongoDB documents are similar to JSON objects. Field values can include other documents, arrays and document arrays
MongoDB features
- MongoDB is a database oriented to document storage, which is relatively simple and easy to operate.
- You can create data mirroring locally or through the network, which makes MongoDB more scalable.
- If the load increases (more storage space and stronger processing power are required), it can be distributed on other nodes in the computer network. This is called sharding.
- Mongo supports rich query expressions. The query commands use JSON format tags to easily query the embedded objects and arrays in the document.
- MongoDb can use the update() command to replace the completed document (data) or some specified data fields.
- Map/reduce in Mongodb is mainly used for batch processing and aggregation of data.
- Map and Reduce. The Map function calls emit(key, value) to traverse all the records in the collection, and passes the key and value to the Reduce function for processing.
- GridFS is a built-in function in MongoDB that can be used to store a large number of small files.
- MongoDB allows scripts to be executed on the server side. You can write a function in Javascript and execute it directly on the server side. You can also store the definition of the function on the server side and call it directly next time.
- MongoDB supports various programming languages: RUBY, PYTHON, JAVA, C++, PHP, C# and many other languages.
- MongoDB is easy to install.
- Fast execution
MongoDB installation
Install under Windows
Download file installation
Pay attention to choose the version corresponding to your computer
Whether to choose the graphical management interface
installation complete
Configuration
server-side mongod
bin directory
client mongo
Log file and data saving
start up
The .msi installation in the new version comes with a configuration file, so we only need to start it once.
Server: mongod
Client: mongo
Install under Mac
Download and install
The author is using mac, so the focus is still to download and install on mac
Enter /usr/local
cd /usr/local
download
sudo curl -O https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-5.0.2.tgz
Unzip
sudo tar -zxvf mongodb-macos-x86_64-5.0.2.tgz
Rename to mongodb directory
sudo mv mongodb-macos-x86_64-5.0.2/ mongodb
Configure environment variables
Since it is in the form of downloading files from the Internet, if you want to use it quickly, you still need to add environment variables
export PATH=/usr/local/mongodb/bin:$PATH
Configure the running data directory and log directory
数据存放路径:
sudo mkdir -p /usr/local/var/mongodb
日志文件路径:
sudo mkdir -p /usr/local/var/log/mongodb
添加读写权限
sudo chown /usr/local/var/mongodb
sudo chown /usr/local/var/log/mongodb
start up
First start the server mongod
mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork
- --dbpath set data storage directory
- --logpath set the log storage directory
- 161443cfab6949 in the background
Check whether the mongod service is started:
ps aux | grep -v grep | grep mongod
Start the client mongo
mongo
The appearance of this interface indicates that the installation is successful
Graphical interface connection
It’s not a problem to use the terminal all the time. Use a graphical tool to connect and use, here DataGrip is used.
Create a new connection
There is nothing to say here. Initially, there is no password. Just connect directly. If a password is configured, please log in with the password.
After the connection is successful, this page will appear on this page
thanks
Universal network
And hardworking self, personal blog , GitHub test , GitHub
Public Account-Guizimo, Mini Program-Xiaogui Blog
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。