Repository navigation
How to get auto assigned id #410
Description
Activity
The key will be automatically populated with the id in its
pathafter the save call. See the docs here for more information.Excerpt:
If a key is incomplete, its associated object is inserted and the original Key object is updated to contain the generated ID.
What version of gcloud-node are you using, and can you paste what your call to
.savelooks like and the returned values to the callback supplied?Thanks for the replies !
Based on the examples of Todo (source, best doc ever) i've used the pop() method on the path to get the ID and now it's working.
Coming for Angular and others JS api i'm quite disturbed with this API paradigm.
I was expecting something like promise or a success and error callback method that send the new ID.Something like save ( ..., onSuccess(id), onFail(err)) and not save (..., cb(err)) if (!err) path.pop().
Or save(...).then(dataFilledWithId)
Have to said this API is quite powerful but sparse on docs. I got my main API running on a java GAE and using GCloud to control it from a nodejs front, it's really cool but it leaves me with a lot of questions on how to use it correctly !
Thanks for the job done :)
The idea is that you create a
keyobject and then you use it to save an object, and later you can use that exact same key object to reference that specific object for future operations.Perhaps we should add some helper methods to the Key object such as
getId()? Would that help?From an old discussion: #175 (comment)
- addedtype: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.api: datastoreIssues related to the Datastore API.Issues related to the Datastore API.
on Mar 31, 2015 Is this resolved? I believe it's relatively straightforward to get the auto-assigned id from the key but let me know if that's not the case.
Is this a bug in the demo ? ... looking at the Todo app sample code the response doesn't return a key. It returns a mutation_result so key.path.pop(); doesn't work. The key should be initialised outside the save function and then the id can be retrieved.
ds.save({ key: ds.key(['TodoList', LIST_NAME, 'Todo']), data: data }, function(err, key) { if (err) { callback(err); return; } data.id = key.path.pop(); callback(null, data); });
I ran the example and
key.pathwas correct:[ 'TodoList', 'default-list', 'Todo', 5720605454237696 ]We do need a better way to get the key and various other helpers. We'll use #574 to track that.
- added a commit that references this issue
on Sep 27, 2022 26 remaining items
- added a commit that references this issue
on Feb 5, 2026 - added a commit that references this issue
on Feb 17, 2026 - added a commit that references this issue
on Feb 23, 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 18, 2026 - added a commit that references this issue
on Mar 27, 2026 - added a commit that references this issue
on May 5, 2026
Using gcloud datastore save leave no indication about the generated ID for the cell.
Nothing in the call back or the key or the data.