show collections in mongodb
db.getCollectionNames()
how to list all collections from a database in mongodb node js
var mongo = require('mongodb').MongoClient;
async function connect(){
/**
* Connection URI. Update <username>, <password>, and <your-cluster-url> to reflect your cluster.
* See https://docs.mongodb.com/ecosystem/drivers/node/ for more details
*/
const uri = "yourUri";
const client = new mongo(uri);
try {
// Connect to the MongoDB cluster
await client.connect();
// Make the appropriate DB calls
const db = client.db("testDatabase");
const collections = await db.collections();
collections.forEach (c=>console.log(c.collectionName));
} catch (e) {
console.error(e);
} finally {
await client.close();
}
}
connect().catch(console.error);
list all collections in the MongoDB shell
JavaScript (shell):
db.getCollectionNames()
Node.js:
db.listCollections()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us