поднял контейнр docker-compose.yml
version: '3.1'
services:
mongo:
image: mongo
restart: always
ports:
- 27021:27021
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
пробую подключиться к БД через pymongo, но конект не происходит получаю ошибку:
pymongo.errors.ServerSelectionTimeoutError: connection closed, Timeout: 30s, Topology Description: <TopologyDescription id: 5f7f2b5f8ba7181b5ec82b55, topology_type: Single, servers: [<ServerDescription ('localhost', 27021) server_type: Unknown, rtt: None, error=AutoReconnect('connection closed')>]>
через mongo-express вижу БД и могу с ней работать.
вот код на py:
from pymongo import MongoClient
client = MongoClient("mongodb://root:example@localhost:27021/")
db = client["admin"]
col = db["system.users"]
x = col.find_one()
print(x)