To list all collections in MongoDB, connect with mongosh, switch to the database with use <database> and run show collections. To list all databases, run show dbs. show tables does the same as show collections. This post shows each command with real output, the script-friendly versions (db.getCollectionNames() and the C# driver), and the reasons a database or collection can seem to be missing from the list.

- List all collections in MongoDB: use a database, then show collections
- List all databases in MongoDB: show dbs
- Connect to MongoDB with mongosh
- List databases and collections from C# or a script
- Why is my database or collection missing from the list?
- What was tested and what was not
- Summary
- MongoDB list collections FAQ
List all collections in MongoDB: use a database, then show collections
Collections belong to a database, so first switch to it (or connect with the database name in the connection string, see below):
use BooksstoreDb
show collections
show tables is an alias and prints the same list. Output from my test database:
BooksstoreDb> show collections
Authors
Books
CheapBooks [view]
Prices [time-series]
system.buckets.Prices
system.views
Views and time series collections are tagged. The list also contains internal system.* collections, which exist because the database has a view and a time series collection. Commands are described in mongosh shell help commands (MongoDB docs).
The same list as an array: db.getCollectionNames()
In scripts you usually want an array. db.getCollectionNames() returns the names (db.getCollectionNames() (MongoDB docs)), and db.getCollectionInfos() adds the type:
db.getCollectionNames()
db.getCollectionInfos({}, { nameOnly: true })
[ 'Authors', 'Books', 'system.views', 'Prices', 'system.buckets.Prices', 'CheapBooks' ]
[
{ name: 'Authors', type: 'collection' },
{ name: 'Books', type: 'collection' },
{ name: 'system.views', type: 'collection' },
{ name: 'Prices', type: 'timeseries' },
{ name: 'system.buckets.Prices', type: 'collection' },
{ name: 'CheapBooks', type: 'view' }
]
To keep only plain collections, filter by type: db.getCollectionInfos({ type: "collection" }, { nameOnly: true }). In my test it returned Authors, Books, system.views and system.buckets.Prices.
List all databases in MongoDB: show dbs
show dbs
test> show dbs
BooksstoreDb 28.00 KiB
Shop 8.00 KiB
admin 8.00 KiB
config 12.00 KiB
local 8.00 KiB
show databases is an alias for show dbs. The sizes are on-disk sizes. For a script, the array form is db.getMongo().getDBNames(), which returned [ 'BooksstoreDb', 'Shop', 'admin', 'config', 'local' ]. The server command behind this is listDatabases command (MongoDB docs).
Connect to MongoDB with mongosh
Start the shell with a connection string. If the string includes a database name, you are already in it and can run show collections straight away:
mongosh "mongodb://127.0.0.1:27017/BooksstoreDb"
mongosh "mongodb://127.0.0.1:27017" # connects to the default test database
Replace the host and port with your own, and add credentials if your server requires them (Connect to a deployment with mongosh (MongoDB docs)). If your system answers that the command is not recognized, see mongo is not recognized as an internal or external command. Older tutorials, including the first version of this post, start the shell with the mongo command; everything here was run in mongosh, and I did not test the old shell. To create or drop what you list, see creating, dropping and renaming a MongoDB database and collection.
List databases and collections from C# or a script
For a one-off script, --eval prints the result and exits:
mongosh "mongodb://127.0.0.1:27017/BooksstoreDb" --quiet --eval 'printjson(db.getCollectionNames())'
In a .NET app, use the driver. This program (MongoDB.Driver 3.14.1, .NET 10) printed the same databases and collections as mongosh:
using MongoDB.Driver;
var client = new MongoClient("mongodb://127.0.0.1:27017");
Console.WriteLine("Databases:");
foreach (var name in await (await client.ListDatabaseNamesAsync()).ToListAsync())
Console.WriteLine($" {name}");
var db = client.GetDatabase("BooksstoreDb");
Console.WriteLine("Collections in BooksstoreDb:");
foreach (var name in await (await db.ListCollectionNamesAsync()).ToListAsync())
Console.WriteLine($" {name}");
Getting started with the driver is covered in getting started with MongoDB in .NET Core.
Why is my database or collection missing from the list?
- The database is empty.
show dbslists databases that hold data. I ranuse Emptyand thenshow dbs: Empty was not listed because it had no collections. - You are in the wrong database. The prompt shows the current one. Without a database in the connection string it is
test. - Permissions. The MongoDB docs say the list of databases depends on your access authorizations. I did not test a restricted user.
- Internal collections.
system.viewsandsystem.buckets.*appear when the database has views or time series collections. Filter them as shown above.
What was tested and what was not
- Run on macOS with MongoDB Community Server 8.2.1 and mongosh 2.14.3: show dbs, show databases, use, show collections, show tables, getCollectionNames, getCollectionInfos, getDBNames, the connection string with a database name, the empty database case, and the C# program with MongoDB.Driver 3.14.1 on .NET 10. All output above is copied from those runs.
- Not tested: the legacy mongo shell, MongoDB Atlas and mongodb+srv connection strings, authentication, sharded clusters, and other server versions.
Summary
- Collections:
use <database>thenshow collections(orshow tables). Databases:show dbs. - For scripts use
db.getCollectionNames(),db.getMongo().getDBNames()or the driver’s list methods. - A database that is empty does not appear in
show dbs.
Found this useful?
Bookmark this page and share it with your team. Get new .NET, cloud and database tutorials in your inbox.
MongoDB list collections FAQ
How do I list all collections in MongoDB?
Connect with mongosh, switch to the database with use followed by its name, then run show collections. In a script, db.getCollectionNames() returns the names as an array.
What is the difference between show collections and show tables in MongoDB?
None. show tables is an alias for show collections in mongosh, and both printed the same list in my test.
Why does show dbs not list my database?
show dbs lists databases that contain data, so a database with no collections does not appear until you insert a document or create a collection. Also check that you are connected to the right server and that your user may list databases.
Did the list match what you expected? Tell us in the comments.
