如何删除documents odm中的多个文档?在PHP类中,我应该能够使用以下代码完成此操作:
$db->collection->remove(array("age" => 18));
我怎么才能在理论mongo odm中做到这一点呢?
发布于 2012-07-02 23:48:04
您有两个选择。使用DocumentManager,您可以请求给定类的集合。这实际上将返回一个Doctrine\MongoDB\Collection
实例,该实例包装了基本MongoCollection
以支持日志记录和事件。如果你真的想要,底层的MongoCollection
也是可用的:
$collection = $dm->getDocumentCollection('Documents\User');
$collection->remove(array('age' => 18));
// Use the raw MongoCollection to bypass logging and events
$mongoCollection = $collection->getMongoCollection();
$mongoCollection->remove(array('age' => 18));
或者,您可以使用query builder API
$qb = $dm->createQueryBuilder('Documents\User');
$qb->remove()
->field('age')->equals(18)
->getQuery()
->execute();
如果止步于Doctrine,则可以在返回的query对象上使用debug()
方法来查看将对数据库执行什么getQuery()
。
https://stackoverflow.com/questions/11300362
复制相似问题