1 initialization
After you create the database, you can type MONGO directly (if the port is the default 27017)
Use admin--Select Admin Database
Db.createuser ({User: ' admin ', pwd: ' admin123 ', roles: [{role: ' Root ', db: ' Admin '}]})
The user is then shown to be successfully added
2 Connecting the database
There are two ways to access the database afterwards
The first of these is:
1mongo 2use admin 3db.auth (' admin ', ' admin123 ')
The second type is
Mongo-u admin-p [Email protected]# 127.0.0.1/admin
I think it's the first way to remember something.
If you do not do this, your operation under the database will show no authorization
3 Adding and removing users
Db.createuser ({User: ' admin ', pwd: ' admin123 ', roles: [{role: ' Root ', db: ' admin '} '}) This is similar to the previous operation
User role has root read write ReadWrite
But must be under the corresponding database, or the operation is very cumbersome
4 Adding data
db.Hello.insert({name:‘World‘})
db.Hello.find()
Python3 using the MONGO database