-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.5.8
-
Component/s: None
-
None
-
(copied to CRM)
-
Empty show more show less
When using 3.5.8 driver with secondaryPreferred and useUnifiedTopology the driver seems to send admin commands like collMod to a secondary.
const { MongoClient } = require('mongodb'); const url = 'mongodb://localhost/?replicaSet=replset&authSource=admin&readPreference=secondaryPreferred&retryWrites=true'; (async () => { const client = await MongoClient.connect(url , { useUnifiedTopology: true }) const db = await client.db('media-providers'); try { await db.collection('tests', { strict: true }); } catch (err) { await db.createCollection('tests'); } try { const result = await db.command({ collMod: 'tests', validator: { $jsonSchema: { type: 'object', properties: { score: { type: 'number' } } } } }); console.log('result', result); } catch (err) { console.error(err); } })();
this gives :
MongoError: not master at MessageStream.messageHandler (/home/dev/node_modules/mongodb/lib/cmap/connection.js:261:20) at MessageStream.emit (events.js:210:5) at processIncomingData (/home/dev/node_modules/mongodb/lib/cmap/message_stream.js:144:12) at MessageStream._write (/home/dev/node_modules/mongodb/lib/cmap/message_stream.js:42:5) at doWrite (_stream_writable.js:431:12) at writeOrBuffer (_stream_writable.js:415:5) at MessageStream.Writable.write (_stream_writable.js:305:11) at TLSSocket.ondata (_stream_readable.js:727:22) at TLSSocket.emit (events.js:210:5) at addChunk (_stream_readable.js:309:12) { operationTime: Timestamp { _bsontype: 'Timestamp', low_: 30, high_: 1591872518 }, ok: 0, code: 10107, codeName: 'NotMaster', '$clusterTime': { clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 2, high_: 1591872519 }, signature: { hash: [Binary], keyId: [Long] } }, name: 'MongoError' }
Setting readPreference to primaryPreferred OR removing
{ useUnifiedTopology: true }resolves the problem (seemingly by sending the administrative command to the primary as expected).
- related to
-
PHPC-1639 Manager::executeCommand() should not inherit read preference
- Closed
-
PHPLIB-558 Database::command() should not inherit read preference
- Closed