2
votes

Looking at the example at: http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/query-builder-api.html

I am unable to do a simple increment. That is the value of "votes" never changes. My document ID ($postID) is correct and I am able to fetch the document. Just unable to increment. Why is Mongo's documentation so out of whack??

$postID = "5121d0ad253b4af1d8000001";
 $dm = $this->get('doctrine.odm.mongodb.document_manager');
$post = $dm->createQueryBuilder('MainPostsBundle:Post')
->field('id')->equals($postID)
->field('votes')->inc(1)
->getQuery()->execute();
1
Try to add ->update() juste after your $dm->createQueryBuilder('MainPostsBundle:Post') - MatRt
that actually worked. However I really would have liked to be able to get a value of votes in the same statement. That is a update/select statement - kratos
What do you have in your $post ? - MatRt
I checked that :) It is a bool. The frustrating part is that the documentation gives you the assumption that you can do an update/select in one statement. - kratos
I'm not sure that all Database implementation (Mysql, PostGreSql...etc) support the UPDATE RETURNING value. But its not a shame to make a second query (select) juste after your update. - MatRt

1 Answers