I created a MongoDb sharded cluster with 2 shards and one of the shards is in another guest machine. The cluster has authorization enabled. And just to solve this problem I created a super user with root role. What Im trying is to create a connector by this config and create my topics;
{
"name": "pms-20",
"config": {
"connector.class": "io.debezium.connector.mongodb.MongoDbConnector",
"mongodb.connection.string":"mongodb://user2:1@192.168.2.5:27030/?authMechanism=SCRAM-SHA-256&authSource=admin&directConnection=true",
"topic.prefix": "eys",
"mongodb.poll.interval.ms": "5000",
"database.history.kafka.bootstrap.servers": "192.168.2.4:29092",
"heartbeat.interval.ms": "5000",
"collection.include.list": "wins.business,wins.tasks",
"capture.mode": "change_streams_with_pre_image"
}
}
My mongos is exposed on 27030. But when I send this request to the debezium Im getting these errors
Caused by: com.mongodb.MongoCommandException: Command failed with error 13 (Unauthorized): 'command aggregate requires authentication' on server 192.168.2.5:27023. The full response is {"ok": 0.0, "errmsg": "command aggregate requires authentication", "code": 13, "codeName": "Unauthorized", "lastCommittedOpTime": {"$timestamp": {"t": 1709881534, "i": 1}}, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1709881541, "i": 2}}, "signature": {"hash": {"$binary": {"base64": "7fJJ7z0jglTmQUik3fL7bAndAxk=", "subType": "00"}}, "keyId": 7343563481024561176}}, "operationTime": {"$timestamp": {"t": 1709881534, "i": 1}}}
Caused by: com.mongodb.MongoCommandException: Command failed with error 13 (Unauthorized): 'command aggregate requires authentication' on server 192.168.2.4:27020. The full response is {"ok": 0.0, "errmsg": "command aggregate requires authentication", "code": 13, "codeName": "Unauthorized", "lastCommittedOpTime": {"$timestamp": {"t": 1709881535, "i": 1}}, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1709881541, "i": 2}}, "signature": {"hash": {"$binary": {"base64": "7fJJ7z0jglTmQUik3fL7bAndAxk=", "subType": "00"}}, "keyId": 7343563481024561176}}, "operationTime": {"$timestamp": {"t": 1709881535, "i": 1}}}
I tried various roles and privileges but alas didnt work. Debezium version: 2.4 MongoDb version: 6.0 They are both dockerized. Any help is much appreciated.
turns out I need specify the connection mode to sharded. I thought it would discover the cluster but I was wrong. The ports of the shards got me thinking and I asked myself why the heck does it trying to connect to shards, theres a mongo server up and running. And then I looked to the documentation again see that
replica_set: The connector establishes individual connections to the replica set for each shard.
sharded: The connector establishes a single connection to the database, based on the value of the mongodb.connection.string.
Its default is set to replica_set and it was trying to connect to each shard. It worked perfectly when I added this line
"mongodb.connection.mode":"sharded",
It works now but I need to find out which role and privilege would suit my needs.