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

Command 'db.hostInfo()' does not work for async

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • No version
    • Affects Version/s: 1.6.0
    • Component/s: AsyncWriter
    • Not Needed

      I try to migrate my scripts from legacy shell to new mongosh. In a class constructor I call db.hostInfo(). I cannot read any properties from result:

       

      class HostInfo {
         constructor() {
            this.info = (async () => { return db.hostInfo(); })();
         }
      }
      
      h = new HostInfo()
      
      typeof h.info.system
       => undefined
      

      I tried several variants, none of them is working:

      (async () => { return db.adminCommand({ hostInfo: 1 }) })();
      (async () => { return JSON.parse(db.hostInfo()) })();
      (async () => { return db.hostInfo().toString() })();
      (async () => { return db.hostInfo().system })();
      (async () => { return db.hostInfo().system.toString() })();
      

      According to https://www.mongodb.com/docs/mongodb-shell/write-scripts/limitations/ I would it expect to work (it was working fine in legacy shell)

      Kind Regards
      Wernfried

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

              Created:
              Updated:
              Resolved: