Question

I'm attempting to remove references to a document (for the purpose of removing said document) using a $pull update query however nothing appears to be happening.

I can manually run the following Mongo query

db.collection.update({}, {
    $pull: {
        'field': {'$id': ObjectId("xxxxxxxx")}
    }
}, false, true)

which works fine. Attempting to do the same in Doctrine's ODM yields neither the expected result or any error messages. Here's what we have so far

$id = new MongoId("xxxxxxxx");

$qb = $repo->createQueryBuilder();
$qb->update();
$qb->field('field')->pull(array('$id' => $id));
$qb->getQuery()->execute();

Any hints about what I'm doing wrong?

Was it helpful?

Solution

Ah, finally found it after trawling through the Doctrine code...

Have to pass the multi option through to MongoCollection::update()

$qb->getQuery(array('multiple' => true))->execute();

OTHER TIPS

 $friend = Zend_Registry::get('doctrine')->getDocumentManager()->createQueryBuilder('App\document\Message')->update()->field('unread')->set(TRUE)->field('viewer_id')->equals(10001)-> getQuery(array('multiple' => true))->execute();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top