Repository navigation
datatstore: Provide a way to get the generated ID from a Key object #171
Description
Activity
Any thoughts for how to provide this? An
idproperty on the Key object? Exposing agetIdmethod to return the last item in thepatharray (would that even work?)?This also got me thinking. Well, 1: we don't have a
putmethod, but I assume you meantsave:) And 2: if it's not too much magic, we could update thekeyobject reference passed in tosave, as opposed to only returning a new key object in the callback. The callback would behave as it currently does, but would also update the original key object.If you have an idea for an implementation, I'm happy to give it a shot.
Exposing a getId method to return the last item in the path array (would that even work?)?
This would work.
But we should additionally provide a pseudo getter for the full path as well. Parent entity keys should be recoverable as well.
The callback would behave as it currently does, but would also update the original key object.
This doesn't fix the problem of not being able to read the ID. You would like to use the ID somewhere else (e.g. as a key to memcache or on the URL to the item's detail page).
We should at least have a
getIdandgetPathbefore the release.Look what @proppy has done https://github.com/proppy/gcloud-node-todos/blob/master/server.js#L31 :)
This doesn't fix the problem of not being able to read the ID.
Nope, was just to be a convenience, since currently you would be left with 2 keys that were meant to refer to the same thing. I'll give it a shot, then run it by you via PR.
- added a commit that references this issue
on Sep 4, 2014 #175 should fix this issue. I'll work on the second part soon.
It sounds like we decided against providing this feature. The link to @proppy's code shows how you can get the id:
key.path_.pop(); // possibly `key.path.pop()` soon.
Re-open if I was mistaken, and this feature can be achieved reliably.
- addedapi: datastoreIssues related to the Datastore API.Issues related to the Datastore API.
on Feb 2, 2015 - added🚨This issue needs some love.This issue needs some love.triage meI really want to be triaged.I really want to be triaged.
on Apr 6, 2020 - added a commit that references this issue
on Aug 22, 2022 50 remaining items
- added a commit that references this issue
on Feb 24, 2026 - added a commit that references this issue
on Feb 26, 2026 - added a commit that references this issue
on Mar 5, 2026 - added a commit that references this issue
on Mar 5, 2026 - added a commit that references this issue
on Mar 11, 2026 - added a commit that references this issue
on Mar 12, 2026 - added a commit that references this issue
on Mar 12, 2026 - added 2 commits that reference this issue
on Mar 23, 2026 - added a commit that references this issue
on Mar 27, 2026 - added a commit that references this issue
on May 5, 2026