In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
* Connect to MongoDB
On this machine, you can directly run the command mongo to enter the mongodb shell
If the mongodb listening port is not the default 27017, you need to add the-- port option when connecting, for example
Mongo-port 27018
To connect to a remote mongodb, you need to add-- host, for example
Mongo-- host 127.0.0.1
If authentication is set, you need to connect with a user name and password
Mongo-uusername-ppasswd / / this looks a lot like MySQL
Exit the database
Ctrl+d
* MongoDB user Management
First of all, mongodb users are for the library. When you set up a user, you need to enter the corresponding library first.
Use test / / switch to the test library. If the library test does not exist, it will be created automatically.
Db.createUser ({user: "admin", pwd: "123456", roles: [{role:'dbOwner',db:'userdb'}]})
Use admin / / switch to the admin library
Db.system.users.find () / / lists all users and must switch to the admin library
Show users / / View all users under the current library
Db.dropUser ('admin') / / Delete user
For user roles, refer to the documentation http://bbs.51cto.com/thread-1146654-1.html
Answer questions after class:
Question: db.createUser ({user: "admin", pwd: "123456", roles: [{role:'dbOwner',db:'userdb'}]}) Why didn't userdb see it?
A: the userdb here is a non-existent library, and its meaning here is to specify which library the user is the owner of.
Q: 1. What libraries or users were originally available after mongodb was installed?
2. There was originally a locla library, but after the user was created, the admin library was added, but there was still no test library.
3. The created user cannot log in to the database.
Answer: 1. After entering, directly show dbs to see, in the initial state, there are no users
2. The test library needs to create a specific collection to appear.
3. To log in, you need to turn on authentication. Http://theadorelee.com/index.php/archives/60.html
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.