-
Type:
Bug
-
Resolution: Won't Fix
-
Priority:
Major - P3
-
None
-
Affects Version/s: 3.6.0
-
Component/s: None
-
None
-
None
-
Not Needed
-
None
-
None
-
None
-
None
-
None
-
None
When directConnection=false is given, the expected behavior is for the driver to discover the topology. This does not seem to be happening in my testing of 3.6.0 driver.
I am starting with the code sample here: https://docs.mongodb.com/drivers/node/usage-examples/insertOne
Test 1 - single host + directConnection=false:
const { MongoClient } = require("mongodb"); const uri = "mongodb://localhost:14071/?retrywrites=false&directconnection=false" const client = new MongoClient(uri); async function run() { try { await client.connect(); const database = client.db("sample_mflix"); const collection = database.collection("movies"); // create a document to be inserted const doc = { name: "Red", town: "kanto" }; const result = await collection.insertOne(doc); console.log( `${result.insertedCount} documents were inserted with the _id: ${result.insertedId}`, ); } finally { await client.close(); } } run().catch(console.dir);
Result:
serene% node test.js (node:7276) 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. MongoError: not master at Connection.<anonymous> (/home/w/apps/tests/retryable-writes-node/node_modules/mongodb/lib/core/connection/pool.js:451:61) at Connection.emit (events.js:315:20) at processMessage (/home/w/apps/tests/retryable-writes-node/node_modules/mongodb/lib/core/connection/connection.js:452:10) at Socket.<anonymous> (/home/w/apps/tests/retryable-writes-node/node_modules/mongodb/lib/core/connection/connection.js:621:15) at Socket.emit (events.js:315:20) at addChunk (_stream_readable.js:295:12) at readableAddChunk (_stream_readable.js:271:9) at Socket.Readable.push (_stream_readable.js:212:10) at TCP.onStreamRead (internal/stream_base_commons.js:186:23) { operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1596644733 }, ok: 0, code: 10107, codeName: 'NotMaster', '$clusterTime': { clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1596644733 }, signature: { hash: [Binary], keyId: 0 } } }
Expected result: I expected the driver to discover the topology and send my insert to the primary.
Test 2 - multiple hosts:
const { MongoClient } = require("mongodb"); const uri = "mongodb://localhost:14070,localhost:14071/?retrywrites=false&directconnection=false" const client = new MongoClient(uri); async function run() { try { await client.connect(); const database = client.db("sample_mflix"); const collection = database.collection("movies"); // create a document to be inserted const doc = { name: "Red", town: "kanto" }; const result = await collection.insertOne(doc); console.log( `${result.insertedCount} documents were inserted with the _id: ${result.insertedId}`, ); } finally { await client.close(); } } run().catch(console.dir);
Result:
serene% node test2.js (node:7330) 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. MongoError: seed list contains no mongos proxies, replicaset connections requires the parameter replicaSet to be supplied in the URI or options object, mongodb://server:port/db?replicaSet=name at connectCallback (/home/w/apps/tests/retryable-writes-node/node_modules/mongodb/lib/operations/connect.js:358:23) at /home/w/apps/tests/retryable-writes-node/node_modules/mongodb/lib/operations/connect.js:599:14 at Mongos.<anonymous> (/home/w/apps/tests/retryable-writes-node/node_modules/mongodb/lib/topologies/mongos.js:224:11) at Object.onceWrapper (events.js:422:26) at Mongos.emit (events.js:315:20) at Server.<anonymous> (/home/w/apps/tests/retryable-writes-node/node_modules/mongodb/lib/core/topologies/mongos.js:416:21) at Object.onceWrapper (events.js:422:26) at Server.emit (events.js:315:20) at Pool.<anonymous> (/home/w/apps/tests/retryable-writes-node/node_modules/mongodb/lib/core/topologies/server.js:384:12) at Pool.emit (events.js:315:20)
I expected the same behavior as in the previous test, for the driver to discover the topology using both seeds.
If I request unified topology, both cases work as expected:
const client = new MongoClient(uri,{useUnifiedTopology:true});
Since the driver default is to not use unified topology, I expected the driver to either:
- Fail client creation when directConnection=false (or any value) is specified without unified topology with an error message stating that the option is only usable in unified topology, or
- Implement the expected directConnection behavior when not in unified topology.
Test cases: https://github.com/p-mongo/tests/tree/master/node-2749