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 operation of mongodb 3.6.6 under Centos7

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Introduction to the basic Operation mongodb of mongodb 3.6.6 under Centos7

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.

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 in relational databases, and it also supports indexing data.

Open multi-instance cp-p / etc/mongod.conf / etc/mongod2.conf## to copy a configuration file to the second instance vim / etc/mongod2.conf## configure instance path: / data/mongodb/mongod2.log # # log file location dbPath: / data/mongodb/mongo # # data location port: 27018 # # different ports of different instances mkdir-p / data/mongodb/ # # Create data folder cd / data/mongodb/mkdir mongo touch mongod2.log # # create log file chmod 777 mongod2.log # # give log file permission mongod-f / etc/mongod2.conf # # Open the second instance mongo-port 27018 # # enter database basic operations > use mydb # # create a database. It will be created if it does not exist. If you do not create a collection, delete > db.createCollection ('a') # # create a collection > db.a.insert ({"id": 1) "name": "zhangsan"}) # # insert data into the collection > db.a.find () # # View data in the collection > a=db.users.findOne ({"id": 2}) # # find the specified record and give it an alias a > typeof (a.id) # # View attribute type > db.users.update ({"id": 10}) {$set: {"name": "tom"}) # # change data > show collections # # View Collection > db.a.drop () # # Delete Collection > db.dropDatabase () # # Delete Database > db.copyDatabase ("mydb" "mydb1") # # copy database import export data mongoexport-d kgc-c users-o / opt/users.json # # Export mongoimport-d kgc-c user1-- file users.json # # Import mongoexport-d kgc-c user1-Q'{"id": {"$eq": 10}'- o / opt/top10.json # # backup and restore mkdir / backupmongodump-d kgc-o / backup/ # according to conditions Backup mongorestore-d kgc2-- dir=/backup/kgc # # restore clone collection mongo-- port 27018 # # enter another instance db.runCommand#### ({"cloneCollection": "kgc.users" "from": "192.168.100.100 db.createUser 27017") # # complete clone creation Administration user > use admin > db.createUser ({"user": "root", "pwd": "123", "roles": ["root"]}) # # user name Password, permission > db.auth ("root", "123") # # to verify

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

Database

Wechat

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

12
Report