Dears,
-
When i updated to mongodb from 3.6.2 to 3.6.3 when i connect to the DB it throws error if useUnifiedTopology is set to true
-
Here is the snippet of the code (ommited username, password and db) using typescript
import { MongoClient } from 'mongodb';
async function initDB() {
const mongoClient = new MongoClient(
'mongodb://***:***@192.168.45.20:27020/db?authSource=admin&readPreference=primaryPreferred&ssl=false', {
useNewUrlParser: true,
useUnifiedTopology: true
})
const client = await mongoClient.connect()
const data = await client.db().collection('providers').find().toArray()
return data
}
initDB().then((result) => {
console.log(`result`, result)
}).catch((err) => {
console.log(`err`, err)
});
MongoServerSelectionError: getaddrinfo ENOTFOUND bawq-server
at Timeout._onTimeout (/mnt/d/work/playground/node_modules/mongodb/lib/core/sdam/topology.js:438:30)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: 'rs1',
maxSetVersion: 1,
maxElectionId: 7fffffff0000000000000001,
servers: Map(1) { 'bawq-server:27020' => [ServerDescription] },
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: 9
}
}
But if useUnifiedTopology
is set to false, it gives me warning , works fine and it gives me the results i expected
(node:2464) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring
engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
Any help about this?
Edit: the problem only exists when using replica set (standalone) when i disable replica set option in config it works fine