show all collections 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);

3.78
9
Jaymos 70 points

                                    async function connect(){
    /**
     * Connection URI. Update &lt;username&gt;, &lt;password&gt;, and &lt;your-cluster-url&gt; to reflect your cluster.
     * See https://docs.mongodb.com/ecosystem/drivers/node/ for more details
     */
    const uri = &quot;yourUri&quot;;
 

    const client = new mongo(uri);
 
    try {
        // Connect to the MongoDB cluster
        await client.connect();
        
        // Make the appropriate DB calls
        const db = client.db(&quot;testDatabase&quot;);
       
        const collections = await db.collections();
        collections.forEach (c=&gt;console.log(c.collectionName));

        }
        
        
 
        // Make the appropriate DB calls
       
 
    } catch (e) {
        console.error(e);
    } finally {
        await client.close();
    }
}

connect().catch(console.error);

3.78 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
find all collections of mongo db node mongodb list all collections in all database nodejs see mongodb database collection show all documents in a collection mongodb node js show collections mongodb node js how to show all collections in mongodb atlas in node print collections in database mongodb in node js node js mongodb list collections list collections in mongodb nodejs get all collections in mongodb node js get all available collections in mongodb node node list db in the mongodb mongodb find all list collection data nodejs collections mongodb find all nodejs show all collections in mongo mongodb get all documents in collection nodejs query all collections mongodb nodejs mongodb node js get all collections how to get all collections name in mongodb node js how to get all collections in mongodb node js how to get all collections in mongodb node js list all collections in mongodb node js get all documents in collection mongodb node js show all collections in mongodb mongodb node js get all documents in collection mongodb show all collections in a db mongodb see all collections node js mongodb client read all collections nodejs list collections in mongodb node mongodb show collections node js how to see collections in mongodb shell db list collections how to get all collection names in mongodb node driver show all records in collection mongodb mongodb show all collections show collections mongodb nodejs show all collections in mongodb node js how to list all collections from a database in mongodb node js
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source