开发者

Doctrine Mongo update $pull query not working

开发者 https://www.devze.com 2023-03-30 01:52 出处:网络
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'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?


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();


 $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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号