我试图使用flask在MongoDB中使用下面的代码创建字段
import pymongo
from pymongo import MongoClient
myclient = MongoClient("mongodb://<username>:<password>@ds119406.mlab.com:19406/")
mydb = myclient["my_database"]
mycol = mydb["my_collection"]
# print(mydb.list_collection_names())
db = myclient.database
print(db)
mydict = {"team_name": "team1" }
x = mycol.insert_one(mydict)
print(x.inserted_id)
已在URI中传递了正确的凭据,但我得到以下错误
操作失败:身份验证失败,完整错误:{'ok':0.0,'errmsg':'Authentication failed','code':18,'codeName':'AuthenticationFailed','operationTime':时间戳(1600853835,1),'clusterTime':{'clusterTime':时间戳(1600853835,1),'signature':{'hash':b'\xa7\xe7\xff\xc0\xde\xff\x8a\xda\xcd\xf8\xddx\x03\xeb\x01\xae\x03\xc5\xb3G','keyId':6829134799643344898}
我的应用程序目前被托管在Google Colaboratory上。关于如何解决这个问题有什么见解吗
我已经解决了这个问题。我使用的凭据仅限于某些数据库,因此我必须在url中指定感兴趣的数据库
相关问题 更多 >
编程相关推荐