You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@mlucy suggested having a third value for the return_changes flag return_changes = "keys".
This would return only the primary keys of the inserted documents, regardless of how they were generated.
I suggest return_changes = ["key1", "key2", etc.]. This is equivalent to calling pluck("key1", "key2", etc.) on the documents in changes, but easier to write and with better performance.
It seems bad to have another syntax for the same thing. I think it's rare enough to want the values of multiple keys that it would be ok to just force them to do a manual pluck on it
We use generated_keys a lot, but exclusively for inserts where we just sent all the data that document will contain - save the generated primary key.
I would be comfortable switching to a flag on return_changes to get the primary key(s) back, or any method that avoids returning the entire document(s) we just inserted.
What exactly would we return for return_changes = "keys"?
Currently we return an array of objects {new_val: <new value>, old_val: <old value>} if return_changes == true.
Should we then return {new_val: <old pkey>, old_val: <new pkey>} or something like {new_val: {<pkey fieldname>: <old pkey>}, old_val: {<pkey fieldname>: <new pkey>}}?
The second option would be as if pluck(<pkey fieldname>) had been applied on the new_val and old_val fields, while the former would be like a getField.
I think I would prefer the slightly more compact {new_val: <old pkey>, old_val: <new pkey>} option.
Yet another alternative could be to just return an array of the new primary keys, since an update cannot change the primary key anyway. This is the most compact representation, but less consistent with return_changes = true.
I'd prefer the getField semantics. We can also just drop the old_val field in this case since it's always null anyway, but I'm not sure how others feel about that (/cc @mlucy).
This was discussed further up, but missing in the latest proposal: We should also support the return_keys option with replace (compare #5752 ).
For both insert with the new conflict-resolution function option as well as for replace, there is the question of whether the keys result field should include keys of all modified documents or only of inserted documents. If it only contains inserted documents, I think we might want to rename it to inserted_keys. Though at that point I'm thinking that we should also have replaced_keys and deleted_keys fields... which makes @deontologician 's idea of having a return_changes "light" that returns a list of {old_key: ..., new_key: ...} pairs sound like the more consistent option in my opinion.
We discussed elsewhere (I forget where) having {error: ... } documents when inserts fail. How do we express that when we don't have the changefeed format, but rather a list of keys that were successfully inserted?
I'm not sure if the keys/generated_keys field should have the {error: } variant. I assumed it would only contain keys of documents that were actually inserted.
However I'm warming up to the idea of just having it be a reduced return_changes variant. In that case it should behave exactly like return_changes, except that it would only return the primary keys of the documents rather than their full contents. It should also have an "always" option in that case.
The issue of not having an error document is that we can't tell which value in an insert failed. We don't know the keys yet, so the only way to determine which one failed is the offset in the insert batch. If we are silent on error, the rest of the inserted keys all correspond to the wrong documents.
Edit: alternately, you can of course requery all of the successful ids and use process of elimination based on some other info you know about in the documents
Activity
danielmewes commentedon Jan 26, 2015
@mlucy suggested having a third value for the
return_changesflagreturn_changes = "keys".This would return only the primary keys of the inserted documents, regardless of how they were generated.
timmaxw commentedon Jan 26, 2015
I suggest
return_changes = ["key1", "key2", etc.]. This is equivalent to callingpluck("key1", "key2", etc.)on the documents inchanges, but easier to write and with better performance.deontologician commentedon Jan 26, 2015
It seems bad to have another syntax for the same thing. I think it's rare enough to want the values of multiple keys that it would be ok to just force them to do a manual pluck on it
danielmewes commentedon Jan 26, 2015
I also think it's enough to support this only for the primary key, without being able to specify arbitrary fields that you want to have returned.
If we want to do this in a more general way, the argument to
return_changescould be a pathspec object. But again I think that's not necessary here.kofalt commentedon Jan 31, 2015
We use
generated_keysa lot, but exclusively for inserts where we just sent all the data that document will contain - save the generated primary key.I would be comfortable switching to a flag on
return_changesto get the primary key(s) back, or any method that avoids returning the entire document(s) we just inserted.coffeemug commentedon Feb 3, 2015
👍
timmaxw commentedon Feb 3, 2015
I'd be fine with
return_changes="keys".danielmewes commentedon Feb 4, 2015
What exactly would we return for
return_changes = "keys"?Currently we return an array of objects
{new_val: <new value>, old_val: <old value>}ifreturn_changes == true.Should we then return
{new_val: <old pkey>, old_val: <new pkey>}or something like{new_val: {<pkey fieldname>: <old pkey>}, old_val: {<pkey fieldname>: <new pkey>}}?The second option would be as if
pluck(<pkey fieldname>)had been applied on thenew_valandold_valfields, while the former would be like agetField.I think I would prefer the slightly more compact
{new_val: <old pkey>, old_val: <new pkey>}option.Yet another alternative could be to just return an array of the new primary keys, since an
updatecannot change the primary key anyway. This is the most compact representation, but less consistent withreturn_changes = true.coffeemug commentedon Feb 4, 2015
I'd prefer the
getFieldsemantics. We can also just drop theold_valfield in this case since it's alwaysnullanyway, but I'm not sure how others feel about that (/cc @mlucy).31 remaining items
danielmewes commentedon May 9, 2016
This was discussed further up, but missing in the latest proposal: We should also support the
return_keysoption withreplace(compare #5752 ).For both
insertwith the new conflict-resolution function option as well as forreplace, there is the question of whether thekeysresult field should include keys of all modified documents or only of inserted documents. If it only contains inserted documents, I think we might want to rename it toinserted_keys. Though at that point I'm thinking that we should also havereplaced_keysanddeleted_keysfields... which makes @deontologician 's idea of having areturn_changes"light" that returns a list of{old_key: ..., new_key: ...}pairs sound like the more consistent option in my opinion.I think we might need to re-discuss this.
deontologician commentedon May 9, 2016
We discussed elsewhere (I forget where) having
{error: ... }documents when inserts fail. How do we express that when we don't have the changefeed format, but rather a list of keys that were successfully inserted?danielmewes commentedon May 11, 2016
I'm not sure if the
keys/generated_keysfield should have the{error: }variant. I assumed it would only contain keys of documents that were actually inserted.However I'm warming up to the idea of just having it be a reduced
return_changesvariant. In that case it should behave exactly likereturn_changes, except that it would only return the primary keys of the documents rather than their full contents. It should also have an"always"option in that case.deontologician commentedon May 11, 2016
The issue of not having an error document is that we can't tell which value in an insert failed. We don't know the keys yet, so the only way to determine which one failed is the offset in the insert batch. If we are silent on error, the rest of the inserted keys all correspond to the wrong documents.
Edit: alternately, you can of course requery all of the successful ids and use process of elimination based on some other info you know about in the documents