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

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);
        db[collectionName].drop()
    }
}

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

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *