Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB listCollections filter

Tags:

mongodb

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?

like image 595
Ricky Avatar asked Jan 30 '18 06:01

Ricky


1 Answers

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.

like image 104
Vince Bowdren Avatar answered Sep 18 '22 12:09

Vince Bowdren