db.getCollectionNames() in mongoDB

getCollectionNames()

This method returns an array containing the names of all collections in the current database. In other words, it returns all the collections in the current database.

Note: If the database does not contain any collections then it will return an empty array.


Syntax:

db.getCollectionNames()


Example 1:When collections present in the database

MongoDB

db.getCollectionNames()

Output:

[ "example", "movies" ]


Example 2: When collections present in the database

MongoDB

db.getCollectionNames()

Output:

[ ]


No comments:

Post a Comment