In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Overview of MongoDB
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.
MongoDB features for collective storage, easy to store object-type data; free schema, support query, support dynamic query; support full indexing, including internal objects; support replication and fault recovery; use efficient binary data storage, including large objects (such as video, etc.); automatically handle fragmentation to support scalability at cloud computing level; support multiple languages such as RUBY,PYTHON,JAVA,C++,PHP,C# The file is stored in BSON (an extension of JSON); it is accessible over the network. Install MongoDB# in Linux install yum source warehouse cd / etc/yum.repos.d/vim mongodb-org.repo [mongodb-org] name=MongoDB Repositorybaseurl= 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# install MongoDByum install mongodb-org-y # modify configuration file vim / etc/mongod.conf# modify the listening address bindIp on line 30: 0.0.0.The "enable systemctl start mongod.service# to disable firewall and security features systemctl stop firewalld.service setenforce" to view the service port status netstat-ntap | grep mongod# replication configuration file To open multi-instance cp-p / etc/mongod.conf / etc/mongod2.conf#, modify line 10 of the configuration file vim / etc/mongod2.conf#, modify line 14 of the log file directory path: / var/log/mongodb/mongod2.log#, and modify line 29 of the data storage directory dbPath: / data/mongodb/mongo# Modify the service port number port: 270ports create the instance directory and log files mkdir-p / data/mongodbcd / data/mongodb/mkdir mongotouch mongod2.log# directory authorization chmod 777 mongod2.log# start the instance mongod-f / etc/mongod2.conf # specify the instance port mongo-- port 270ports view service port status netstat-ntapMongoDB basic operation # View version db.version () # View database show dbs # View the connection address of the current database machine db.getMongo () # display the collection operation command db. Collection name .help # shows user show users
Add, delete, modify and check
Use school # Open the school database. It will be created if it does not exist. Delete db.createCollection ('info') # create collection db.info.insert ({"id": 1, "name": "zhangsan", "hobby": ["game") "talk"]}) # add data db.info.find () # View all documents in the info collection show collections # View all collections db.info.update in the database ({"id": 10} {$set: {"name": "tom"}) # change data db.info.remove ({"id": 2}) # remove data from id2 in info collection db.info.drop () # delete info collection db.dropDatabase () # delete database first use to the database to be deleted before deleting db.info.count () # count the number of data MongoDB data type String# strings Most commonly used, must be utf-8Boolean# Boolean value, true or falseInteger# integer Double# floating point Arrays# array or list, multiple values are stored in a key Object# for embedding document, that is, a value is a document Null# stores null value Binary Data # binary data, used to store binary data Date# stores the current date or time unix time format
View data types
A=db.info.findOne ({"id": 1}) # find the specified record and give it an alias aypeof (a.id) # View attribute type backup and restore data
Export tool: mongoexport
Import tool: mongoimport
Common options:
-port: represents the database address of the remote connection, and connects to the local Mongo database by default;-- port: the port that represents the database of the remote connection, and the default remote port 27017, which represents the account that connects to the remote database. If you set the authentication of the database, you need to specify the user account;-pmaewaypassword: the password corresponding to the account that connects to the database. -type: represents the exported file type, including csv and json files;-o,-- out: represents the exported file name;-Q,-- query: represents the query condition -- skip: skip the specified amount of data;-- limit: read the specified number of data records;-- sort: sort the data, you can specify the sorted fields by parameters, and use 1 and-1 to specify the sorting method, where 1 is an ascending sort, while-1 is used for descending sorting, such as sort ({KEY:1}). For (var iTunes 1)
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.