Skip to content

Deprecate the generated_keys field #3074

Open

Description

@deontologician

generated_keys:

  • doesn't include keys created by r.uuid (which is confusing)
  • is opt-out
  • is significantly less useful when any inserts fail

The return_changes flag:

  • subsumes its functionality entirely
  • is easier to use in the face of failed inserts (by design)
  • is opt-in
  • shares the same interface as changefeeds, making it fit in better

I think we should deprecate generated_keys and remove it in a few releases.

Activity

  1. added this to the subsequent milestone on Sep 18, 2014
  2. modified the milestones: 2.0, subsequent on Jan 26, 2015
  3. danielmewes commented on Jan 26, 2015

    @danielmewes
    Member

    @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.

  4. timmaxw commented on Jan 26, 2015

    @timmaxw
    Member

    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.

  5. deontologician commented on Jan 26, 2015

    @deontologician
    ContributorAuthor

    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

  6. danielmewes commented on Jan 26, 2015

    @danielmewes
    Member

    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_changes could be a pathspec object. But again I think that's not necessary here.

  7. kofalt commented on Jan 31, 2015

    @kofalt

    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.

  8. coffeemug commented on Feb 3, 2015

    @coffeemug
    Contributor

    a third value for the return_changes flag return_changes = "keys".

    👍

  9. timmaxw commented on Feb 3, 2015

    @timmaxw
    Member

    I'd be fine with return_changes="keys".

  10. danielmewes commented on Feb 4, 2015

    @danielmewes
    Member

    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.

  11. coffeemug commented on Feb 4, 2015

    @coffeemug
    Contributor

    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).

  12. 31 remaining items

  13. modified the milestones: , on Mar 26, 2015
  14. danielmewes commented on May 9, 2016

    @danielmewes
    Member

    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.

    I think we might need to re-discuss this.

  15. deontologician commented on May 9, 2016

    @deontologician
    ContributorAuthor

    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?

  16. danielmewes commented on May 11, 2016

    @danielmewes
    Member

    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.

  17. deontologician commented on May 11, 2016

    @deontologician
    ContributorAuthor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions