我尝试使用python pymongo远程连接到MongoDb服务器,但是当我尝试从集合中显示文档时,我收到了错误消息
" pymongo.errors.OperationFailure:未授权在pt上执行命令{find:" devices",filter:{}}"
此外,当我尝试从mongo获取单个记录时,它不会显示记录详细信息,而是显示为
" pymongo.cursor.Cursor对象位于0x000001E883A14F98"。
Mongo服务器详细信息:主持人:Someth-pt-ved-01 用户:uname pwd:mypass authenticationDatabase:pt 集合:设备
我的连接python代码是:
from pymongo import MongoClient
uri = "mongodb://uname:mypass@Someth-pt-ved-01:27017"
client = MongoClient(uri)
db = client.pt
collection = db.devices
#to get single record details
cursor = collection.find({'ID': 1490660})
print(cursor)
#to get all documents from collection-devices
for document in cursor:
print(document)
请注意;我正在使用Windows 10。