Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-568

Improve deprecation error for setSlaveOk

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.10.0
    • Affects Version/s: 0.7.7
    • Component/s: Shell API
    • None
    • 1
    • Not Needed

      Tab completion on a secondary won't work without setting the appropriate read preference.

      rs0 [direct: secondary]> db.slaTab completion error: MongoError: not master and slaveOk=false
          at MessageStream.messageHandler (/home/alex/Workspace/mongo/mongosh:46582:20)
          at MessageStream.emit (events.js:315:20)
          at MessageStream.EventEmitter.emit (domain.js:486:12)
          at processIncomingData (/home/alex/Workspace/mongo/mongosh:43478:12)
          at MessageStream._write (/home/alex/Workspace/mongo/mongosh:43374:5)
          at writeOrBuffer (_stream_writable.js:352:12)
          at MessageStream.Writable.write (_stream_writable.js:303:10)
          at Socket.ondata (_stream_readable.js:719:22)
          at Socket.emit (events.js:315:20)
          at Socket.EventEmitter.emit (domain.js:486:12) {
        topologyVersion: { processId: ObjectId("601c0d6951aabc0c661dc8d2"), counter: 4 },
        ok: 0,
        code: 13435,
        codeName: 'NotPrimaryNoSecondaryOk',
        '$clusterTime': {
          clusterTime: Timestamp(1, 1612451538),
          signature: {
            hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
            keyId: 0
          }
        },
        operationTime: Timestamp(1, 1612451538)
      

      However SERVER-49990 removes `setSlaveOk` which users are used to and the MongoError still alludes to.

      rs0 [direct: secondary]> db.getMongo().setSlaveOk(true)
      MongoshDeprecatedError: [COMMON-10003] setSlaveOk is deprecated.
      

      Trying to set slaveOk does not point users to anything relevant. If you discover the alias (SERVER-49990) and try this the error is a little more helpful at least:

      rs0 [direct: secondary]> db.getMongo().setSecondaryOk(true)
      MongoshDeprecatedError: [COMMON-10003] Setting secondaryOk is deprecated, use setReadPref instead
      

      Making the setSlaveOk and setSecondaryOk errors the same would at least make this a little easier for users to action. Adding documentation links to the errors would be even better

            Assignee:
            sergey.petushkov@mongodb.com Sergey Petushkov
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: