Kostas Xafis
Kostas Xafis

Reputation: 104

How to get the list of my database's collection names

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šŸ§”!

Upvotes: 0

Views: 1068

Answers (1)

Kostas Xafis
Kostas Xafis

Reputation: 104

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...

Upvotes: 1

Related Questions