1
votes

I'm using Doctrine MongoDB ODM with Symfony 2.0.5

This code causes no effect:

 $dm = $this->get('doctrine.odm.mongodb.document_manager');
        $dm->createQueryBuilder('AcmeMyBundle:Entry\Entry')
            ->field('comments2')->push('some text')
            ->field('_id')->equals($entry_id) 
            ->getQuery()
            ->execute();

The symfony profiler says that actual query is:

db.entries.find({ "_id": ObjectId("4ea97d482fd1288017000000") }).sort([ ]);

What is wrong with it?

1

1 Answers

2
votes

You need to specify that the query type is an update.

    $dm = $this->get('doctrine.odm.mongodb.document_manager');
    $dm->createQueryBuilder('AcmeMyBundle:Entry\Entry')
        ->update()
        ->field('comments2')->push('some text')
        ->field('_id')->equals($entry_id) 
        ->getQuery()
        ->execute();