简体   繁体   中英

auth failed - mongodb - pymongo - k8s

I'm trying to connect into mongodb with pymongo, but i can't import data or create a collection.

This is the code to connect into mongo:

db_local = pymongo.MongoClient("mongodb://mongodb-service.default.svc.cluster.local:27017", username="admin", password="pass")

mydb_local= db_local["test"]

And then i tried this to create new collection:

mydb_local.create_collection("HDFS"]

While trying to add the collection i get this error:

Authentification failed., full error: {'ok': 0.0, 'errmsg': Authentification failed.', 'code: 18, 'codeName': AuthentificationFailed'}

Meanwhile, i deployed Mongodb into Minikube, and this is the mongodb-sercret.yaml file:

apiVersion : v1
kind: Secret 
metadata: 
    name: mongodb-secret
type: Opaque
data : 
     mongo-root-username : dXNlcm5hbWU=
     mongo-root-password : cGFzc3dvcmQ=

PLease try this:

db_local= pymongo.MongoClient("mongodb://admin:pass@mongodb-service.default.svc.cluster.local:27017")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM