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

'rs.status()' failed when replicaset is not initialized

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.6.0
    • Affects Version/s: 1.3.1, 1.5.0
    • Component/s: CLI Module
    • None
    • 3
    • Needed
    • Hide

      mongosh adds a `-json` CLI flag with possible `json=canonical` and `json=relaxed` flags, the default being `canonical`. When used, mongosh will print Extended JSON as output. This flag can only be used in conjunction with `eval`, and is mutually exclusive with `-shell` and providing files on the command line.

      Errors and regular output are not distinguished based on the output alone, only in the exit code of mongosh. Repeated errors while trying to serialize the output to Extended JSON will not be serialized.

      Show
      mongosh adds a `- json` CLI flag with possible ` json=canonical` and ` json=relaxed` flags, the default being `canonical`. When used, mongosh will print Extended JSON as output. This flag can only be used in conjunction with ` eval`, and is mutually exclusive with ` -shell` and providing files on the command line. Errors and regular output are not distinguished based on the output alone, only in the exit code of mongosh. Repeated errors while trying to serialize the output to Extended JSON will not be serialized.
    • Iteration Grouper, Iteration Herring, Iteration Isopod, Iteration Jellyfish

      When you run rs.status() on a replicaset which is not yet initialized then you get an error:

      mongosh --norc localhost:27017
      
      test> rs.status()
      Uncaught:
      MongoServerError: no replset config has been received
          at MessageStream.messageHandler (C:\Programs\MongoDB\Server\bin\mongosh.exe:101152:20)
          at MessageStream.emit (events.js:400:28)
          at MessageStream.emit (domain.js:475:12)
          at processIncomingData (C:\Programs\MongoDB\Server\bin\mongosh.exe:100448:12)
          at MessageStream._write (C:\Programs\MongoDB\Server\bin\mongosh.exe:100344:5)
          at writeOrBuffer (internal/streams/writable.js:358:12)
          at MessageStream.Writable.write (internal/streams/writable.js:303:10)
          at Socket.ondata (internal/streams/readable.js:731:22)
          at Socket.emit (events.js:400:28)
          at Socket.emit (domain.js:475:12) 

      However, according documentation and in legacy mongo shell it should return a JSON with proper error code:

      mongo --norc localhost:27017
      
      > rs.status()
      {
              "ok" : 0,
              "errmsg" : "no replset config has been received",
              "code" : 94,
              "codeName" : "NotYetInitialized"
      } 

      I deploy MongoDB with scripts, and not getting a proper JSON response makes it much more difficult to automate the deployment process.

       

            Assignee:
            anna.henningsen@mongodb.com Anna Henningsen
            Reporter:
            wernfried.domscheit@sunrise.net Wernfried Domscheit
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: