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
Determine conflict strategy for inserts with a function #3753
Comments
Good idea. We should support it in the same way as #873 . |
Just ran into this as well. I'm basically looking to do a table.insert(values, {
conflict: function (old_val, new_val) {
return old_val.pluck('foo', 'bar').merge(new_val);
}
}) |
I like the idea of passing the conflict resolution function as a |
We should also consider making the format be |
Bumping to subsequent; #873 got bumped and we should settle this at the same time (hopefully for 2.2). |
Is this happening on 2.1 or 2.2? Now I need to insert in batches with conflict = update and there is a field that could be missing when updating that I would like to add(but only if it doesn't exist). Are there any alternatives? |
@thelinuxlich This is not happening for 2.1, hopefully for 2.2. Sorry. Assuming that you need this to be atomic, I'm not sure if there's a work-around at the moment. |
I don't think there's any way to do this while preserving the performance benefits of batched inserts in 2.0 or 2.1. Hopefully we can get this in for 2.2. |
Bumping to 2.2 polish. |
@danielmewes oops, sorry. At first glance I was thinking (as you just said) that the callback would be fired for every document with |
Looks like we agree on .insert(documents, {conflict: function(id, old_val, new_val) { ... } }) where the conflict function is only called when there actually is a conflict. |
Another very good use case for this feature would be when you save timestamps for document updating and when replacing in batches, you want to drop documents which have a older timestamp than the document to be replaced, thus guaranteeing some kind of ordering. |
@thelinuxlich Very interesting use case! |
I found another use case, when you want to limit the key quantity of a embedded object, very useful. |
@thelinuxlich what do you mean? Can you give an example where that's useful? |
@marshall007 when you let the user save N fields inside a embedded object but you want to limit the max quantity of fields. An example from my code(limiiting to 30 fields):
|
This was in review #3523. |
This is in next. |
I'm inserting in batches with conflict: replace, but I stumbled upon a case where I'd need to change the strategy to error if the field status of my data is false. Without the possibility to do this dynamically I will have to avoid batch inserting for this specific table.
The text was updated successfully, but these errors were encountered: