show collections in mongodb
db.getCollectionNames()
list all collections in the MongoDB shell
JavaScript (shell):
db.getCollectionNames()
Node.js:
db.listCollections()
show collection data in mongodb
db.collectionName.find()
show all collections in mongodb node js
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));
}
// Make the appropriate DB calls
} catch (e) {
console.error(e);
} finally {
await client.close();
}
}
connect().catch(console.error);
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