Search code examples
mongodbnode-mongodb-native

mongodb: number of collections in database - native driver


I'm using the mongodb native driver v3.2.3 and trying to query how many collections are in the current database. I thought it would be

db.listCollections()

But this does not appear to return a count.


Solution

  • You can get the collection count of a database via the stats method:

    let stats = await db.stats();
    console.log(stats.collections);