Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic installation and operation of MongoDB

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Main points: MongoDB introduces the basic operation of linux system installation MongoDBMongoDB. 1. 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.

2. Linux system installation MongoDB: step 1: configure YUM source warehouse [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 step 2: install MongoDByum install mongodb-org-y modify configuration file: vim / etc/mongod.confbindIp: 0.0.0.0 / / listener address port: 27017 / / listener port 2, Enable service: systemctl start mongod.servicenetstat-natp | grep 270173, start MongoDB multi-instance: cp-p / etc/mongod.conf / etc/mongod2.confvim / etc/mongod2.conf / / modify the following code: path: / data/mongodb/mongod2.log / / log file directory dbPath: / data/mongodb/mongo / / data storage directory port: 27018 / / server port 4, Create the directory and log files of the instance: mkdir-p / data/mongodb/cd / data/mongodb/mkdir mongotouch mongod2.logchmod 777 mongod2.log5, launch the instance: mongod-f / etc/mongod2.conf mongo-- port 27018 / / specify the port of the instance netstat-ntap 3, MongoDB basic Operations 1, basic commands:

(1) documents: rows equivalent to relational databases (multiple documents form a collection)

(2) Collection: a table equivalent to a relational database (multiple collections make up the database)

(3) the special function of database name:

Admin: add a user to the library, who inherits all permissions in the database

Local: this library is never replicated and can be stored in any collection limited to a single local server

Config: when Mongo is used for sharding settings, this library is used internally to save information about sharding.

Mongo / / enter the database

> db.version () / View version > show dbs; / / View Database > db.getMongo () / / View the connection address of the current database machine > db. Collection name .help / / Show collection operation command > show users / / display user (4) specific operation: > use school / / Open the school database. If it does not exist, it will be created. If you do not create a collection, delete > db.createCollection ('info') / / create a 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 in the database > db.info.update ({"id": 10} {$set: {"name": "tom"}) / / change the data > db.info.remove ({"id": 2}) / / remove the data from the id2 in the info collection > db.info.drop () / / delete the info collection > db.dropDatabase () / / delete the database first use to the database to be deleted before deleting > db.info. Count () / / count how many pieces of data there are (5) MongoDB data type: String: string Most commonly used, must be utf-8Boolean: Boolean, true or falseInteger: integer Double: floating point Arrays: array or list, multiple values are stored in a key Object: used to embed a document, that is, a value is a document Null: store null values Binary Data: binary data Used to store binary data Date: store current date or time unix time format (6) View data type: > a=db.info.findOne ({"id": 1}) / / find the specified record and give it an alias a > typeof (a.id) / / View attribute type 2, backup, Restore: (1) Import export: export: mongoexport import: mongoimport common options:-d database-c collection-o directory file .json ending-Q export data filter condition-f which columns are exported for (var iTunes 1) I use admin > db.createUser ({"aaa": "root", "pwd": "123"," roles ": [" root "]}) / / create user aaa password 123123 assigned to root role > db.auth (" root "," 123123 ") / / authenticate user

4. Process management:

Terminate a running process: db.killOp (opid value)

View the currently running process: db.currentOp ()

> db.currentOp () / / View > db.killOp (4872) / / terminate the 4872 process

5. MongoDB monitoring:

MongoDB provides some built-in tools to monitor the status of the database

View the status information of the database instance: db.serverStatus ()

View database statistics: db.stats ()

In addition, you can also view the system monitoring information through the web interface. You need to add it to the configuration file.

Vim / etc/mongod.confhttpinterface=true

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report