I'm trying to get a list of all collections with a query, except site and stat_site

$collections = $db->getCollectionNames(array('name'=> array('$nin' => array('site','stat_site')))); 

A list of all the collections comes out, and these too. How to exclude them correctly?

    2 answers 2

    Use the listCollections method, specifying the required restrictions in the filter option:

     $collections = $db->listCollections(array( 'filter' => array( 'name' => array( '$nin' => array('site', 'stat_site') ) ) )); 
       $collections = $db->getCollectionNames(); unset($collections(array_search('site', $collections))); unset($collections(array_search('stat_site', $collections)));