2

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();
kratos
  • 2,465
  • 2
  • 27
  • 45
  • 3
    Try to add `->update()` juste after your `$dm->createQueryBuilder('MainPostsBundle:Post')` – MatRt Feb 24 '13 at 23:17
  • 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 Feb 25 '13 at 01:09
  • What do you have in your `$post` ? – MatRt Feb 25 '13 at 02:39
  • 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 Feb 25 '13 at 02:54
  • and that bool is true whether update goes through or not. Ha Ha – kratos Feb 25 '13 at 02:59
  • 1
    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 Feb 25 '13 at 03:00

1 Answers1