-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting driver wide collection options for safe, fsync and timeout. #32
base: master
Are you sure you want to change the base?
Conversation
Perfect. I was about to do that myself (make update operations accept extra parameters other than 'multiple' => true). But thanks for getting ahead. I still changed something related to updates; see here: #31 |
Cool. :) FYI - There was a bug in my insert, which is fixed now. :) I was also thinking of extending it a little further with a mechanism that lets colection_options be set for one request only (I dont always need safe mode set for everything). I'll model it on http://book.cakephp.org/view/1045/Creating-and-Destroying-Associations-on-the-Fly#!/view/1045/Creating-and-Destroying-Associations-on-the-Fly - Like binding the options for one request only. |
That is a better approach. At first I thought of passing a third parameter in updateAll so that collection options could be set on demand like you say (something like: Mode->updateAll($fields, $conditions, $mongodb_options). But that would need some override of the Model class' updateAll method, and IMO this is something out of the 'scope' of this plugin. But your suggestion is better. Something like binding. $this->Model->collectionOptions = array('upsert' => true, 'safe' => true. etc.); |
It is not appropriate to use a db-wide options array on multiple collections - and on function calls that are expecting different options to be used.
It's likely that if you want to modify these settings, you want them different for specific collections and probably specific operations. By which I mean for example: inserts on [collection] are safe, but updating some counter/timestamp field is not a safe update. Therefore, while these changes may scratch your current itch it doesn't really solve "the problem". I'd suggest that where currently you reference |
Hi Andy, Thanks for the feedback and fair point. To expand on your suggestion, should the options in $Model->mongoOptions[$methodname] be set by $Model->setMongoOptions(array('save' => array('safe'), 'insert' => array('safe','fsync','upsert','timeout' => n), ...)); Cheers |
elricho - personally I'd go with simple - if (!empty($Model->...)) - but Ichi might have a different idea, and it's his code. However, if it works (by any means) it would be simple to make it work better before/after merging. |
sorry too late reply. Thanks great idea and discussion. |
if (!empty($data['_id'])) { | ||
$this->_convertId($data['_id']); | ||
$cond = array('_id' => $data['_id']); | ||
unset($data['_id']); | ||
|
||
$data = $this->setMongoUpdateOperator($Model, $data); | ||
|
||
$params = array_merge($this->collectionOptions['update'], array("multiple" => true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$params = array_merge($this->collectionOptions['update'], array("multiple" => false));
Hi Ichi, line 112: line 742: |
…nsion. Tests updated. Composer added.
Enable extension in php 5.6 & 7.0 Add php 7.0 as test target (will this work with cakephp 2.8?)
BugFix : Add try/catch blocks to all database calls.
Presently there is no way to set safe, fsync and timeout collection options for creates and updates.
This patch implements a driver field 'collection_options' => array(...)
The array can take 'safe' => n, 'fsync' => true/false, 'timeout' => n
See http://www.php.net/manual/en/mongocollection.save.php for more informaiton on field settings.