TL;DR
Trying to connect from service in default namespace to mongodb ops manager replica-set service in mongodb namespace. I tried with all below connection string formats. But, connection getting closed.
- "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user"
- "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user?replicaSet=mongo-replica-set"
- "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017,mongo-replica-set-1.mongo-replica-set-svc.mongodb.svc.cluster.local:27017,mongo-replica-set-2.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user"
- "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017,mongo-replica-set-1.mongo-replica-set-svc.mongodb.svc.cluster.local:27017,mongo-replica-set-2.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user?replicaSet=mongo-replica-set"
- "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user?tls=false&ssl=false"
- "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017,mongo-replica-set-1.mongo-replica-set-svc.mongodb.svc.cluster.local:27017,mongo-replica-set-2.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user?tls=false&ssl=false"
- "mongodb+srv://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/?tls=false&ssl=false"
- "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user?replicaSet=rs0"
Longer Version
I created replicaset deployment in "MongoDB Ops Manager" ( mongodb namespace ) . I am trying to connect to replicaset from another service in default namespace
Replica Set - mongo-replica-set
Number of Nodes - 3
I tried with different connect string format. But, always connection getting closed. I whitelisted multiple IPs I could get from the service.
1.
const MONGO_URI = "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user"
const options = {
useUnifiedTopology: true,
useNewUrlParser: true,
useCreateIndex: true,
keepAlive: true
};
mongoose.connect(MONGO_URI, options);
MongooseServerSelectionError: connection <monitor> to 10.20.1.5:27017 closed
at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:830:32)
at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:335:15)
at /app/src/index.ts:52:20
at step (/app/src/index.ts:33:23)
at Object.next (/app/src/index.ts:14:53)
at /app/src/index.ts:8:71
at new Promise (<anonymous>)
at __awaiter (/app/src/index.ts:4:12)
at start (/app/src/index.ts:5:15)
at Object.<anonymous> (/app/src/index.ts:63:1)
at Module._compile (internal/modules/cjs/loader.js:1201:30)
at Module._compile (/app/node_modules/source-map-support/source-map-support.js:547:25)
at Module.m._compile (/tmp/ts-node-dev-hook-19384996922428388.js:60:25)
at Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
at require.extensions.<computed> (/tmp/ts-node-dev-hook-19384996922428388.js:62:14)
at Object.nodeDevHook [as .ts] (/app/node_modules/ts-node-dev/lib/hook.js:61:7) {
reason: TopologyDescription {
type: 'Single',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(1) {
'mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
const MONGO_URI = "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user?replicaSet=mongo-replica-set"
MongooseServerSelectionError: connection <monitor> to 10.20.1.5:27017 closed
at NativeConnection.Connection.openUri
...
{
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(1) {
'mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
const MONGO_URI = "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017,mongo-replica-set-1.mongo-replica-set-svc.mongodb.svc.cluster.local:27017,mongo-replica-set-2.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user"
MongooseServerSelectionError: connection <monitor> to 10.20.1.5:27017 closed
....
{
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(3) {
'mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription],
'mongo-replica-set-1.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription],
'mongo-replica-set-2.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
const MONGO_URI = "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017,mongo-replica-set-1.mongo-replica-set-svc.mongodb.svc.cluster.local:27017,mongo-replica-set-2.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user?replicaSet=mongo-replica-set"
MongooseServerSelectionError: connection <monitor> to 10.20.1.5:27017 closed
...
{
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(3) {
'mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription],
'mongo-replica-set-1.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription],
'mongo-replica-set-2.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
const MONGO_URI = "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user?tls=false&ssl=false"
MongooseServerSelectionError: connection <monitor> to 10.20.1.5:27017 closed
at NativeConnection.Connection.openUri
....
{
reason: TopologyDescription {
type: 'Single',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(1) {
'mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
const MONGO_URI = "mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017,mongo-replica-set-1.mongo-replica-set-svc.mongodb.svc.cluster.local:27017,mongo-replica-set-2.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user?tls=false&ssl=false"
MongooseServerSelectionError: connection <monitor> to 10.20.1.5:27017 closed
at NativeConnection.Connection.openUri
...
{
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(3) {
'mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription],
'mongo-replica-set-1.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription],
'mongo-replica-set-2.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
const MONGO_URI = "mongodb+srv://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/?tls=false&ssl=false"
MongoParseError: Ports not accepted with 'mongodb+srv' URIs
at parseSrvConnectionString (/app/node_modules/mongodb/lib/core/uri_parser.js:50:21)
at parseConnectionString (/app/node_modules/mongodb/lib/core/uri_parser.js:556:12)
at connect (/app/node_modules/mongodb/lib/operations/connect.js:277:3)
at /app/node_modules/mongodb/lib/mongo_client.js:222:5
at maybePromise (/app/node_modules/mongodb/lib/utils.js:719:3)
at MongoClient.connect (/app/node_modules/mongodb/lib/mongo_client.js:218:10)
at /app/node_modules/mongoose/lib/connection.js:716:12
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:709:19)
at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:335:15)
at /app/src/index.ts:53:20
at step (/app/src/index.ts:33:23)
at Object.next (/app/src/index.ts:14:53)
at /app/src/index.ts:8:71
at new Promise (<anonymous>)
at __awaiter (/app/src/index.ts:4:12)
const MONGO_URI = mongodb://mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017/user?replicaSet=rs0
MongooseServerSelectionError: connection <monitor> to 10.20.1.5:27017 closed
...
{
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map(1) {
'mongo-replica-set-0.mongo-replica-set-svc.mongodb.svc.cluster.local:27017' => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
What am I missing here? Thanks for any help