Trying to get a list of collections from mongoose

Just came across this answer and though it may have worked at the time it appears collectionNames has been removed from the available function names in favour of listCollections

This other stack overflow post has a working example: https://stackoverflow.com/a/29461274/4127352

Here is the link to the original docs: http://mongodb.github.io/node-mongodb-native/2.0/meta/changes-from-1.0/


Try running your collection names function after connection.

mongoose.connection.on('open', function (ref) {
    console.log('Connected to mongo server.');
    //trying to get collection names
    mongoose.connection.db.listCollections().toArray(function (err, names) {
        console.log(names); // [{ name: 'dbname.myCollection' }]
        module.exports.Collection = names;
    });
})