liveBook · Manning

listCollections

As explained in MongoDB 8.0 in Action, Third Edition

listCollections is a MongoDB database command that returns collection metadata and supports filtering collections by properties such as type.

listCollections is a MongoDB database command for inspecting collection metadata. Its filter option narrows results by properties such as collection type, making it useful for locating specialized collections. section 2.6.3

Use the command when you need to:

  • Find every time-series collection in the current database. section 2.6.3
  • Inspect collection metadata without querying collection documents. section 2.6.3
  • Avoid placing collection-listing operations inside transactions, where the command is not permitted. section 8.5

Find time-series collections

Run db.runCommand({ listCollections: 1, filter: { type: "timeseries" } }) to return collections whose type is timeseries. section 2.6.3

Listing 2.5 Listing time-series collections in a database
db.runCommand( {
   listCollections: 1,
   filter: { type: "timeseries" }
} )

Shows the complete mongosh command for filtering a database's collections by the timeseries type. section 2.6.3

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Demonstrates filtered command syntax and notes transaction restrictions, without detailing the returned metadata schema.
Examples
Uses a db.runCommand example filtering collections with { type: "timeseries" }.
What it assumes
Assumes access to a MongoDB database and familiarity with running database commands.
What you can do after
Operate MongoDB by listing collection metadata and filtering results for time-series collections.
How it connects
Connects collection discovery with time-series collections and multidocument transactions.

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.