Verify if insert was successful in Symfony2/Doctrine/MongoDB
-
26-02-2021 - |
Question
My application is not alerting me to a failed insert when adding a record to a MongoDB collection with a unique index...
$dm->flush()
... does not complain. I'm trying to figure out what the array parameter to flush should look like to see if that helps but getting nowhere. flush does not return anything on success or failure.
Any ideas on how I can verify, in my PHP/Symfony2 application, whether the insert worked without needing to query the db immediately after inserting?
Solution
Got it. Per this link, must provide array("safe" => true)
as a parameter to the write operation.
$dm->flush(array('safe'=>true));
So when using the code above and trying to insert into a unique index an exception will be thrown.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow