0

I have briefly searched through the internet but i haven't found anything useful.
My problem is that i can't retrieve the list of my database collections with the the function :
db.listCollections().


So simply what i did is the following:

const db = client.db(db_name);
let colls = db.listCollections() // also tried db.listCollections({}, {nameOnly: true});

But all i get is a large object that doesn't mention any collections. Am i missing something big? I assumed that i would retrieve an array but no luck to that, sooo... can anyone quickly help out here?


Thanks in advance!
  • You can refer to https://stackoverflow.com/questions/8866041/how-can-i-list-all-collections-in-the-mongodb-shell to check how to see list of database collections. – Pramod Sep 08 '20 at 16:16

1 Answers1

1

Okay so apparently by adding :

let colls = db.listCollections().toArray();

was enough. But i dont know why something like that is not mentioned in the documentation...

  • https://docs.mongodb.com/manual/reference/method/db.getCollectionNames/index.html#db-getcollectionnames – Joe Sep 09 '20 at 08:36
  • Yea but this function works only in the mongo shell and not for node. Most of the commands that i had checked would work specifically in the mongo shell. Is there a way to get and store the mongo shell's output from nodejs? – Κωνσταντινος Χαφης Sep 09 '20 at 09:04