How to get all collections of a MongoDB database from a Doctrine DocumentManager?

  backend, doctrine, mongodb, php, symfony

I need to make a Doctrine migration to remove all collections (except for one) from a MongoDB database. This would be equivalent MongoDB code:

var collectionNames = db.getCollectionNames();
for(var i = 0, len = collectionNames.length; i < len ; i++){
    var collectionName = collectionNames[i];
    if(collectionName != 'Collection'){
        print('REMOVED:'+ collectionName);

Is there a way to run it natively in a Doctrine migration, or use DocumentManager to achieve it?

Source: Symfony Questions