Ricky
Ricky

Reputation: 777

MongoDB listCollections filter

I am working with node.js

I am trying to filter the collections I have to exclude the collection 'outlets' and retrieve all other collections, but I can't seem to figure out the syntax. I've tried:

db.listCollections({filter: 'outlets'}).toArray((err, docs)

Any suggestions?

Upvotes: 6

Views: 4035

Answers (1)

Vince Bowdren
Vince Bowdren

Reputation: 9208

Your filter is mis-constructed. Instead of saying 'filter', you have to specify the field to filter by name in a filter document, like this for example:

db.listCollections({name: 'outlets'});

That will include only the outlets collection, however. To exclude the outlets collection, you need to use the $ne operator

db.listCollections({name: {$ne: 'outlets'}});

See the guidance in the docs on the listCollections command for more details.

Upvotes: 5

Related Questions