In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Overview of MongoDB basic installation MongoDB
(1) MongoDB is a database based on distributed file storage. Written in C++ language. Designed to provide scalable high-performance data storage solutions for WEB applications.
(2) MongoDB is a product between relational database and non-relational database, which is the most functional and most like relational database in non-relational database. It supports a very loose data structure, which is similar to json's bson format, so it can store more complex data types. The most important feature of Mongo is that the query language it supports is very powerful, and its syntax is somewhat similar to the object-oriented query language. It can almost achieve most of the functions similar to the single table query of relational database, and also supports the establishment of data indexing.
(3) characteristics:
For collection storage, it is easy to store data of object type
Free mode, support query, support dynamic query
Full indexing is supported, including internal objects
Support for replication and failure recovery
Use efficient binary data storage, including large objects such as video, etc.
Automatically handle fragments to support scalability at the cloud computing level
Support for multiple languages such as RUBY,PYTHON,JAVA,C++,PHP,C#
The file is stored in BSON (an extension of JSON)
Can be accessed through the network.
MongoDB installation process 1, experiment preparation name role address Centos7-1 service carrier 192.168.142.2122, Specific process (1) configure the local YUM source (path location: / etc/yum.repos.d/) [root@promote yum.repos.d] # vim MongoDB.repo [mongodb-org] name=mongodbbaseurl= https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/gpgcheck=1enabled=1gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc (2) install the service ontology and configure / / install MongoDB [root @ Promote yum.repos.d] # yum install mongodb-org-Listen to local interface only / modify configuration file [root@promote yum.repos.d] # vim / etc/mongod.confnet: port: 27017Accord / make the service available to any network bindIp: 0.0.0.0 # Listen to local interface only Comment to listen on all / / enable the service [root@promote yum.repos.d] # systemctl start mongod.service [root@promote yum.repos.d] # netstat-atnp | grep 27017tcp 00 0.0.0.0 systemctl start mongod.service 27017 0.0.0.0 mongo * LISTEN 39695/mongod// enters the MongoDB database [root@promote mongodb] # mongo-- port 27017
At this point, the MongoDB service has been installed, but the experiment will not be over. What we need to start is the extension process of its installation.
(3) establish multiple instances of MongoDB / / after installing MongoDB, [root@promote etc] # cp-p mongod.conf mongod2.conf// modifies the configuration file of the second instance [root@promote yum.repos.d] # vim / etc/mongod2.confsystemLog: destination: file logAppend: true path: / data/mongodb/mongod2.log / / log file path (needs to be different from the first) storage: dbPath: / data/ Mongodb/mongo / / data file path (same) journal: enabled: truenet: port: 27018 / / set a different port number bindIp: 0.0.0.0 # Listen to local interface only Comment to listen on all int// establishes instance 2 site [root@promote etc] # mkdir-p / data/mongodb/ / create instance data storage location [root@promote etc] # cd / data/mongodb/ [root@promote mongodb] # mkdir mongo [root@promote mongodb] # touch mongod2.log// create instance log file location [root@promote mongodb] # chmod 777 mongod2.log// launch Instance 2 [root@promote mongodb] # mongod-f / etc//mongod2.conf [root@promote mongodb] # mongo-- port 27018 / / perform basic MongoDB operations in different instances through different port numbers
Do it in MongoDB
Mysql "> > show dbs/databases # View all databases > show collections/tables # View all collections in the database > db.info.find (condition) # View the contents of the collection example: > db.info.find ({" id ": 20}) # View information with id 20 > use school # No database will be created and entered Without creating the collection, it does not display > db.createCollection ('info') # create the collection (data table) info > db.info.insert ({"id": 10, "name": zhangsan, "key name": value}) # insert the value > db.info.insert ({"hobby": ["game", "read") into the collection "value"]}) # add string array to the collection > a=db.info.find () # alias the search result definition > for (var item11) I db.info.update ({"id": 20} {$set: {"name": "kaili"}) # change data # # change name in id=20 to kaili > db.info.count () # count how much data is in the collection > db.test.drop () # Delete a collection > db.test.remove ({"id": 8}) # Delete a data > db.dropDatabase ( ) # Delete the entire database (if you enter the database) > db.copyDatabase ("school") "shell") # copy school database to shell database (renamed copy) MongoDB import and export
Export
[root@promote mongodb] # mongoexport-d school-c info-o / opt/school.json
"- d" specifies the database
"- c" specifies the collection
"- o" specifies the export path
Import (import database does not exist)
[root@promote mongodb] # mongoimport-d school-c info-- file=/opt/school.json
"--file" specifies the imported json file
Conditional derivation
[root@promote mongodb] # mongoexport-d school-c info-Q'{"id": {"$eq": 20}}'- o / opt/ttt.json
"- Q" condition judgment (greater than: gt; less than: lt; equals: eq. No greater than or equal to, less than or equal to)
MongoDB backup, recovery
Backup
[root@promote mongodb] # mongodump-d school-o / opt/
Restore
[root@promote mongodb] # mongorestore-d school-- dir=/opt/school
"--dir" specifies the backup directory path
Clone a collection in an instance
Premise: in the case of multiple instances of MongoDB
[root@promote mongodb] # mongo-- port 27018 # enter the second instance # Clone the school.info collection from the MongoDB database on port 27017 of this machine into this instance > db.runCommand ({"cloneCollection": "school.info", "from": "192.168.142.212 port 27017"}) create an administrative user > use admin # the database exists by default > db.createUser ({"user": "root") "pwd": "123123", "roles": ["root"]}) # create administrative user "user" # administrative user name "pwd" # password "roles": ["root"] # permission is administrator > db.auth ("root", "123123") # authentication
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.