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

Can't read from secondary

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.1.4
    • Affects Version/s: None
    • Component/s: Shell API
    • None
    • 2
    • Iteration Phnom Penh
    • Not Needed

      Problem Statement/Rationale

      What is going wrong? What action would you like the Engineering team to take?

      Kevins-MDB-MBP:code kevarh$ cat broken.js
      if (typeof rs.secondaryOk !== 'undefined') {
        rs.secondaryOk();
      } else {
        rs.slaveOk();
      }
      printjson(db.getMongo().getDBNames());
      
      Kevins-MDB-MBP:code kevarh$ mongo 127.0.0.1:27018 broken.js
      MongoDB shell version v4.4.0
      connecting to: mongodb://127.0.0.1:27018/test?compressors=disabled&gssapiServiceName=mongodb
      Implicit session: session { "id" : UUID("bbe398b5-de9b-47ec-9182-f156b240cb9e") }
      MongoDB server version: 4.4.3
      [ "admin", "config", "local", "status" ]
      Kevins-MDB-MBP:code kevarh$ mongosh 127.0.0.1:27018 broken.js
      Current Mongosh Log ID:	6192a94e3efa8c88a52515e3
      Connecting to:		mongodb://127.0.0.1:27018/test?directConnection=true&serverSelectionTimeoutMS=2000
      Using MongoDB:		4.4.3
      Using Mongosh:		1.1.2
      
      For mongosh info see: https://docs.mongodb.com/mongodb-shell/
      
      ------
         The server generated these startup warnings when booting:
         2021-11-11T14:18:04.550-06:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
         2021-11-11T14:18:04.550-06:00: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip <address> to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning
      ------
      
      Loading file: broken.js
      DeprecationWarning: .setSecondaryOk() is deprecated. Use .setReadPref("primaryPreferred") instead
      Setting read preference from "primary" to "primaryPreferred"
      MongoServerError: not primary and secondaryOk=false - consider using db.getMongo().setReadPref() or readPreference in the connection string
      

      Steps to Reproduce

      How could an engineer replicate the issue you’re reporting?

      Run the included script.

      Expected Results

      What do you expect to happen?

      Output is equivalent to mongo shell.

      Actual Results

      What do you observe is happening?

      MongoServerError: not primary and secondaryOk=false - consider using db.getMongo().setReadPref() or readPreference in the connection string

      Additional Notes

      Any additional information that may be useful to include.

            Assignee:
            anna.henningsen@mongodb.com Anna Henningsen
            Reporter:
            kevin.arhelger@mongodb.com Kevin Arhelger
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: