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

Commands related to MongoDB database establishment, permissions, and roles

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

1) create a custom database use

Syntax: use database name

Example:

Use goodsdb / / execute in Shell environment

Note: if the goodsdb database does not exist, Bay IJ establishes a new database; if the goodsdb database exists, connect to the database, and then you can do various command operations on the database.

2) View the database show dbs

Syntax: show dbs

Example:

Show dbs / / you can execute this command on any current database

Admin 0. OOOGB / / keep the database, admin

Goodsdb 0. 0 OGB / / Custom database, goods db, in which several records have been inserted

Local O. OOOGB / / keep the database, local

Test O. OOOGB / / keep the database, test

3) Statistics of a database information db.stats ()

Syntax: db .stats ()

Example:

4) Delete database dropdatabase ()

Syntax: db.dropDatabase () / / delete the current database

Example:

Do not use this command casually in a production environment. Because the corresponding database file disappears after the command is executed, under normal circumstances

It is irrecoverable.

5) View the collection name getCollectionN ames () under the current database

Grammar: db. GetCollectionNames () U views the names of all collections under the current database

Example:

Db. GetCollectionNames ()

6) View database user role permissions s how roles

Syntax: show roles / / View the user role permissions, user name, password and other information of the current database

Example:

In the actual production environment, the information obtained by executing the show roles command will change. Technicians can use db .c r e ateUs er to create new user roles, permissions, usernames, passwords, and so on. Modify information such as user roles and permissions with commands in a format similar to the following:

Explain; explain.

(I) it is recommended to establish strict access authorization for Mon go DB access in a production environment to prevent network security problems.

(2) for rapid debugging in the development environment, access without search rights is allowed.

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