Does Doctrine 2 have upsert functionality built in? It doesn't seem to, but I wasn't able to find a definitive yes-or-no answer.
If it does, I would of course be interested to see an example and/or some documentation.
I believe I found the answer. As of today (10/15/2012), there's an open "add upsert support" issue for Doctrine. I assume that this ticket wouldn't still be open if Doctrine 2 did have upsert support, so I guess there's my definitive answer.
Upsert is already present in Doctrine.
Using the query builder, you have to set findAndUpdate() and returnNew() if you want to return the document. Set upsert() and you're ready to go.
For example:
$documentMannager->createQueryBuilder('App\Domain')
->findAndUpdate()
->returnNew()
->field('_id')->equals($id)
->field('page')->equals($page)
->field('count')->inc(1)
->upsert()
->getQuery()
->execute();
This is the way i implement a bucket pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With