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
