Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2823

createIndex can fail with "MongoError: not master" in v3.6.0+ with a non-primary read preference

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.6.0
    • Component/s: None
    • None

      This issue appears to be a regression of NODE-680 and was introduced as a result of https://github.com/mongodb/node-mongodb-native/commit/38bcaf7c80f63885d4c0cf1f7389819efb0664e6#diff-aa40aa8bcfc7826a48153f27cc6a7c7cL44 associated with NODE-2569.

      The following reproduction will fail in v3.6.2 but succeed in v3.5.10:

      var MongoClient = require('mongodb').MongoClient
      
      const url = 'mongodb://localhost:27017,localhost:27018,localhost:27019/?replSet=replset&readPreference=secondary';
      
      async function main() {
        const client = new MongoClient(url,{
          keepAlive: true,
          connectTimeoutMS: 30000,
          socketTimeoutMS: 30000,
          useNewUrlParser: true,
          useUnifiedTopology: true
        });
        client.on('connectionCheckOutStarted', event => console.dir(event));
        await client.connect((err, client) => {
          if (err) throw err;
        });
        const collection = client.db('foo').collection('bar');
        await collection.createIndex({ baz: 1 });
        process.exit(1);
      }
      main();
      

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: