当前位置:网站首页>Introduction of mongod management database method

Introduction of mongod management database method

2022-07-07 15:19:00 1024 questions

Today, I mainly understand database management , Before operation MongoDB Service open .

One 、 Display database inventory

If you want to view the database list, you can use show dbs.

Two 、 Switch database

By using MongoDB Built in handle in db To perform database operations . When operating on different databases , have access to db.getSiblings(database) Method or use <database>.

db=db.getSiblingDB('testDB')use testDB

Both of the above methods switch the current database handle to testDB, And put db Set the value of to the specified database .

3、 ... and 、 Create database

MongoDB Not provided shell The command to create the database shown in . have access to <new_database_name> Create a new database handle , But unless you add the collection to a new database , Otherwise it will not actually be saved . In the following screenshot, create a new database handle and execute show dbs The original database is still displayed . After adding the collection, there will be a new database .

Four 、 Delete database

If there is a creation display, there will definitely be a deletion , Deleting a database is also very simple and practical dropDatabase() Method . above show dbs You can see that there are three databases , Use dropDatabase() Then let's see how many .

You can see that after deleting one, there are still 2 A database ,3-1=2 Well

5、 ... and 、 Copy database

Copying a database will create a database that is exactly the same except for its name , It is generally used for backup or archiving .

Create a copy of the database , You can switch to this database , And then use copyDatabase(origin,destination,[hostname]) To create a copy .origin The argument is a string , Specify the name of the database to be copied ,destination Parameters are specified here MongoDB The name of the database to be created on the server . Optional hostname Parameter assignment origin database MongoDB The hostname of the server ( If you copy databases from different hosts ). The screenshot below is to create a new newDB database , It adds a set and Person, Then create a by copying the database testDB database .show collections You can see that it also exists Person aggregate .

This is about MongoDB This is the end of the article on database management . I hope it will be helpful for your study , I also hope you can support the software development network .


原网站

版权声明
本文为[1024 questions]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071310404312.html