简体   繁体   English

使用 python 连接到 mongodb 地图集时出现问题

[英]Problem connecting to mongodb atlas using python

I have a problem connecting to Mongo.我在连接到 Mongo 时遇到问题。 Would appreciate help.. Thanks将不胜感激帮助..谢谢

client =MongoClient("mongodb+srv://srdht:srdht@srddataset.2htbr.mongodb.net/dbImages?retryWrites=true&w=majority",ssl=True,ssl_cert_reqs='CERT_NONE')
    db=client.get_database('dbImages')
    records = db.atopic
    records.count_documents({})
    new_student = {
        'name': 'ram',
        'roll_no': 321,
        'branch': 'it'
    }
    records.insert_one(new_student)
    new_students = [
        {
            'name': 'alex',
            'roll_no': 320,
            'branch': 'it'
        },
        {
            'name': 'john',
            'roll_no': 30,
            'branch': 'ece'
        }
    ]
    
    records.insert_many(new_students)

and error:和错误:

Traceback (most recent call last):
  File "C:/Users/student/Documents/GitHub/SRD/imageProcessing.py", line 24, in <module>
    **client =MongoClient("mongodb+srv://srdht:srdht@srddataset.2htbr.mongodb.net/dbImages?retryWrites=true&w=majority",ssl=True,ssl_cert_reqs='CERT_NONE')**
  File "C:\Users\student\.windows-build-tools\python27\lib\site-packages\pymongo\mongo_client.py", line 672, in __init__
    connect_timeout=timeout)
  File "C:\Users\student\.windows-build-tools\python27\lib\site-packages\pymongo\uri_parser.py", line 453, in parse_uri
    **'%s -m pip install "pymongo[srv]"' % (python_path))
pymongo.errors.ConfigurationError: The "dnspython" module must be installed to use mongodb+srv:// URIs. To fix this error install pymongo with the srv extra:
 C:\Users\student\.windows-build-tools\python27\python.exe -m pip install "pymongo[srv]"**

You need to install the dnspython, try this command to install it:你需要安装 dnspython,试试这个命令来安装它:

python -m pip install pymongo[srv]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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