Mongodb 简单配置和密码访问

1.配置

net:
  port: 27017
  bindIp: 0.0.0.0
security:
  authorization: enabled
systemLog:
  destination: file
  path: "/data/log/mongod.log"
  logAppend: true
storage:
  dbPath: "/data/db"
#processManagement:
#  fork: true

2.创建用户

 

use admin
db.createUser({user: 'root', pwd: '123456', roles: ['root']})
db.auth('root','123456')
use Article
db.createUser({user:'test',pwd:'123456',roles: [{role:'readWrite',db:'Article'}]})

3.pymongo连接

 

mongoClient = pymongo.MongoClient('mongodb://test:123456@localhost:27017/Article')
db = mongoClient['article']
results = db['article'].find({})
for item in results:
    print(item)

 

http://www.waitingfy.com/archives/3363

3363

Leave a Reply

Name and Email Address are required fields.
Your email will not be published or shared with third parties.