[英]how to connect atlas mongodb with a cluster
我正在尝试将我的代码连接到 atlas mongo db,但出现以下错误,这是我的代码:
from pymongo import MongoClient
client = MongoClient("mongodb+srv://username:test@cluster0.yntdf.mongodb.net/test?
retryWrites=true&w=majority")
db = client["test"]
collection = db["test"]
collection.insert_one({"_id":0, "name": "hello", "score": 5})
我得到了错误:
配置错误:A DNS label 为空。
有谁知道如何处理这个错误? 我安装了 dnspython 和 pymongo
您的连接字符串错误。 仔细检查它是否正确,并且调用服务器的 IP 也被列入白名单。
我遇到了同样的问题,以下代码适用于 python 3.9.1
import pymongo
import urllib
MONGODB_USERNAME = urllib.parse.quote_plus('test')
MONGODB_PASSWORD = urllib.parse.quote_plus('tset@000')
MONGODB_DATABASE = 'sampledb'
MONGODB_URL = "mongodb://"+MONGODB_USERNAME+":"+MONGODB_PASSWORD+"@cluster0.wq5js.mongodb.net/"+MONGODB_DATABASE+"?retryWrites=true&w=majority"
client = pymongo.MongoClient(MONGODB_URL)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.