w3resource

MongoDB: db.getCollectionNames() method

db.getCollectionNames

The db.getCollectionNames() method is used to return an array containing the names of all collections in the current database.

Syntax:

db.getCollectionNames()

Example: MongoDB: db.getCollectionNames() method

The following example will return the name of the collection form the current database test.

db.getCollectionNames();

Output

> db.getCollectionNames();
[
        "collection_new",
        "empdetails",
        "invoice",
        "orders",
        "prod_mast",
        "prod_master",
        "restaurants",
        "restaurants_new",
        "system.indexes",
        "system.profile",
        "userdetails"
]

Retrieve the restaurants data from here

Previous: db.getCollection() method
Next: db.getLastError() method



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/mongodb/shell-methods/database/db-getCollectionNames.php