listCollections not giving documented output

Hi All,

listCollections doesn’t appear to give the correct documented output in mongosh (used in Compass).

So I have 3 time series collections in a database XXX

I’ve switched to XXX with this command. use XXX

Then tried: db.runCommand( { listCollections: 1.0 } )

and got:

{
  cursor: {
    id: Long("0"),
    ns: 'aether.$cmd.listCollections',
    firstBatch: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object]
    ]
  },
  ok: 1
}

I’m expecting an output like the one documented here:

Anyone know what’s going on here?

Chris

Hey @Chris_Swainson :wave:

So it’s showing correctly in Compass but not via the mongosh? (Or at least it’s not displaying as you are expecting?)

I haven’t tested this yet but it might be possibly due to the inspectDepth setting on mongosh. Can you try configuring the inspectDepth to a higher value and test again?

Let me know how it goes.

Regards,
Jason

Briefly tested using the example timeseries data from the documentation link you provided and I got the following with an inspectDepth of 2:

db> db.runCommand({listCollections:1.0})
{
  cursor: {
    id: Long("0"),
    ns: 'db.$cmd.listCollections',
    firstBatch: [ [Object], [Object] ]
  },
  ok: 1,
...

Changed inspectDepth value to 10 and got the following output:

db> config.set('inspectDepth',10)
Setting "inspectDepth" has been changed

db> db.runCommand({listCollections:1.0})
{
  cursor: {
    id: Long("0"),
    ns: 'db.$cmd.listCollections',
    firstBatch: [
      {
        name: 'weather',
        type: 'timeseries',
        options: {
          timeseries: {
            timeField: 'timestamp',
            metaField: 'metadata',
            granularity: 'hours',
            bucketMaxSpanSeconds: 2592000
          }
        },
        info: { readOnly: false }
      },
      {
        name: 'system.buckets.weather',
        type: 'collection',
        options: {
          validator: {
            '$jsonSchema': {
              bsonType: 'object',
              required: [ '_id', 'control', 'data' ],
              properties: {
                _id: { bsonType: 'objectId' },
                control: {
                  bsonType: 'object',
                  required: [ 'version', 'min', 'max' ],
                  properties: {
                    version: { bsonType: 'number' },
                    min: {
                      bsonType: 'object',
                      required: [Array],
                      properties: [Object]
                    },
                    max: {
                      bsonType: 'object',
                      required: [Array],
                      properties: [Object]
                    },
                    closed: { bsonType: 'bool' }
                  }
                },
                data: { bsonType: 'object' },
                meta: {}
              },
              additionalProperties: false
            }
          },
          clusteredIndex: true,
          timeseries: {
            timeField: 'timestamp',
            metaField: 'metadata',
            granularity: 'hours',
            bucketMaxSpanSeconds: 2592000
          }
        },
        info: {
          readOnly: false,
          uuid: new UUID("eacd1dcd-6891-4679-9178-5103060e1ae1")
        }
      }
    ]
  },
  ok: 1

Hopefully this is what you were after or helps you out.

Thanks for your quick reply Jason.

Unfortunately I get:

>use xxx
<'switched to db xxx'

>config.set('inspectDepth',10)
<'Option "inspectDepth" is not available in this environment'

Chris

What version of mongosh are you currently using? I’m currently using 1.6.0 on my test environment (for reference).

Additionally, do you get any output when running config? e.g.:

db>config
Map(12) {
  'displayBatchSize' => 20,
  'maxTimeMS' => null,
  'enableTelemetry' => true,
  'editor' => null,
  'snippetIndexSourceURLs' => 'https://compass.mongodb.com/mongosh/snippets-index.bson.br',
  'snippetRegistryURL' => 'https://registry.npmjs.org',
  'snippetAutoload' => true,
  'inspectCompact' => 3,
  'inspectDepth' => 10,
  'historyLength' => 1000,
  'showStackTraces' => false,
  'redactHistory' => 'remove'
}

Jason

I’m using the _MONGOSH terminal at the bottom of Compass.

> config
< {}
> version()
< '1.8.0'

Chris

Ah gotcha - makes sense now.

Going to check if inspectDepth can be configured here…

Regards,
Jason

Does running:

EJSON.stringify(
  db.runCommand( {
     listCollections: 1,
     filter: {}
  })
)

work for you?

Regards,
Jason

Currently it’s not possible to set the inspectDepth in the embedded mongosh shell in MongoDB Compass but hopefully the above workaround suits you for now.

Alternatively, you can download the standalone mongosh shell and configure it from there using the commands I had posted previously.

Regards,
Jason

Thanks for you help Jason,

The work around worked.

It’s not great that for whatever reason the mongosh shell in Compass won’t handle this. Nothing really indicates it’s ‘light’ or ‘minimal’ or ‘beta’ etc.

I’ll get the stand alone version.

Thanks for you time. Very prompt responses and much appreciated.

Chris

1 Like

Glad the workaround worked and thanks for updating the post :slight_smile:

I understand that it’s not ideal that the embedded mongosh shell isn’t able to configure those particular settings at this stage so I’ve raised this internally as a form of feedback.

Regards,
Jason