In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you about the basic operating commands and statements of mongodb. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
To log in to the test library for the first time, you need to switch the admin library and create a user
1. Two kinds of mongo authentication login 1. Similar to mysql authentication login mongo-- host 10.10.10.5-u "testuser"-- authenticationDatabase "admin"-pendant 123456'
Login result
MongoDB shell version v4.0.4connecting to: mongodb://127.0.0.1:27017Implicit session: session {"id": UUID ("a8c4b96d-0b8d-469c-9d6c-7c0bcb38161b")} MongoDB server version: 4.0.42, authentication after login mongoMongoDB shell version v4.0.4connecting to: mongodb://127.0.0.1:27017Implicit session: session {"id": UUID ("88d434a3-a436-4189-929b-5b70f11248db")} MongoDB server version: 4.0.4 >
Toggle admin library
> use adminswitched to db admin > db.auth ("testuser", "123456") 1 II. Create library, view library 1, create database > use testdb # create testdb library switched to db testdb2, view current library > dbtestdb 3, view all libraries > show dbsadmin 0.000GBconfig 0.000GBlocal 0.000GBtestdb 0.000GB
# 4. View the current database user permissions
> show users {"_ id": "admin.testuser", "user": "testuser", "db": "admin", "roles": [{"role": "root", "db": "admin"}], "mechanisms": ["SCRAM-SHA-1" "SCRAM-SHA-256"]} III. Detailed explanation of permission roles.
Create a user to assign permissions 1. Create a super user
In the admin library, create a testuser user, set the password to 123456 and the permission to root
> db.createUser ({user:'testuser',pwd:'123456', roles: [{role:'root', db:'admin'}]}) Successfully added user: {"user": "testuser", "roles": [{"role": "root", "db": "admin"}]} 2. Create ordinary users
In the testdb library, create a testuser user, set the password to 123456 and the permission to dbOwner
> use testdbswitched to db testdb > db.createUser ({user:'testuser',pwd:'123456', roles: [{role:'dbOwner', db:'testdb'}]}) Successfully added user: {"user": "testuser", "roles": [{"role": "dbOwner", "db": "testdb"}]} V. Change password, permissions, etc. 1. Change password
Change the testuser user password to abc123
Method 1 > db.changeUserPassword ("testuser", "abc123") method 2 > db.updateUser ("testuser", {pwd: "abc123"}) 2, modify permission 1 > add permission > db.grantRolesToUser ("testuser", [{role: "readWrite", db: "testdb"}, {role: "read", db: "testdb"}]) 2 > delete permission > db.revokeRolesFromUser ("testuser", [{role: "readWrite", db: "testdb"]) 3 > modify permission > db.updateUser ("testuser") {roles: [{role: "read", db: "admin"}]})
On the basic operation of mongodb commands and statements to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.