如何通过DoctrineMongoDBBundle截断MongoDB集合?

如何通过DoctrineMongoDBBundle截断MongoDB集合?,mongodb,symfony,doctrine-orm,doctrine-odm,Mongodb,Symfony,Doctrine Orm,Doctrine Odm,我有一个mongoDB集合,我想通过编程将其截断(删除此集合中的所有文档)。我这样做: $collection = $this ->container ->get('doctrine_mongodb') ->getRepository('AppBundle:User'); $document_manager = $this ->container ->get('doct

我有一个mongoDB集合,我想通过编程将其截断(删除此集合中的所有文档)。我这样做:

    $collection = $this
        ->container
        ->get('doctrine_mongodb')
        ->getRepository('AppBundle:User');

    $document_manager = $this
        ->container
        ->get('doctrine_mongodb')
        ->getManager();

    if($override){
        $document_manager->remove($collection);

其中User是集合的名称。但它不起作用。如何正确删除集合中的所有文档?

首先,获取集合:

$collection = $document_manager->getDocumentCollection('AppBundle:User'); // or just a class name
$collection->drop();
向集合中的所有文档传递空数组以匹配所有文档:

$collection->remove([]);
收藏:

$collection = $document_manager->getDocumentCollection('AppBundle:User'); // or just a class name
$collection->drop();