GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Returning key identifier as part of data returned by query · Issue #594 · googleapis/google-cloud-node

Returning key identifier as part of data returned by query #594

New issue
Copy link
New issue
Copy link
Closed
Closed
Returning key identifier as part of data returned by query#594
Copy link
Assignees
byrneciaran
Labels
api: datastoreIssues related to the Datastore API.type: questionRequest for information or clarification. Not an issue.
Milestone
Datastore Future

Description

@byrneciaran
byrneciaran
opened on May 13, 2015
Issue body actions

I use the key identifier extensively throughout my app as my "id". The namespace and kind doesn't change. Is it possible to return the key identifier inline with the data returned from queries or should I just include the identifier as a property on the entity ?

For example, if you look at this simple example of an entity returned by a query:

[ { key: { namespace: 'mynamespace', path: [Object] },data: { name: 'My Entity'} }]

What I would like is for my data object to look like:

data:{id:XXXXX,name:'My Entity}

At the moment to include the key identifier with my data object I need to do something like:

var dao = entity.data
dao.id = entity.key.path.pop()

NOTE - I use pop() here since it's in the examples but I think it's a bad idea. Poping the identifier removes it from the path array. If I go on to reuse the key, it's incomplete (e.g. if I did a get and update). I think entity.key.path[entity.key.path.length - 1] is a better idea.

Anyway, if I am returning thousands of entities I can write (using async.js) something like:

 ds.runQuery(query, function(err,entities){
   async.map(entities,DAO,callback);
 });

function DAO(entity,callback) {
  var dao = entity.data;
  dao.id = entity.key.path.pop();
  callback(null, dao);
}

The problem I have is that (1) this is quite cumbersome (2) I haven't benchmarked but I'm sure there is a performance hit.

Is there a better way to do this ?

Activity

Next
  1. jgeewax commented on May 13, 2015

    @jgeewax
    jgeewax
    on May 13, 2015
    Contributor
    More actions

    Some related issues:

    • Provide helper methods on entity.Key for Kind, parent, name, and ID #574 - Add helper methods on key (this would make your code dao.id = entity.id (or dao.id = key.name)
    • Access properties directly from the entity #508 - Access properties directly rather than inside data / id

    I think #574 would solve your issue.


    Regarding key.path.pop(): I can't find anything in the docs -- can you maybe open a separate issue to remove those examples? I think you're right that it's not the best way to get the Key name/id.

  2. jgeewax
    added
    type: questionRequest for information or clarification. Not an issue.
    api: datastoreIssues related to the Datastore API.
    on May 13, 2015
  3. jgeewax
    added this to the Datastore Future milestone on May 13, 2015
  4. byrneciaran commented on May 13, 2015

    @byrneciaran
    byrneciaran
    on May 13, 2015
    Author
    More actions

    Thanks @jgeewax!

    My specific issue refers to retrieving entities. I actually think getting the id is ok when saving an entity as it's only one entity. The problem is that retrieving multiple entities requires something like map to populate the data object.

    This could be resolved by automatically populating the id or name property on the data object returned. This is similar to what happens in MongoDB whereby the _id is automatically set. If you want to exclude to exclude the id or name property you could do so through a projection, but by default it's included.

  5. byrneciaran
    closed this as completedon May 13, 2015
  6. jgeewax commented on May 13, 2015

    @jgeewax
    jgeewax
    on May 13, 2015
    Contributor
    More actions

    Gotcha, @byrneciaran

    Our worry (outlined in #508) is that key isn't a reserved word, so if someone had a property called key, we'd blast it out with the entity key... So we have to figure something out there... Feel free to add your use case over on that issue so we can make sure whatever we decide makes sense for everyone!

  7. JustinBeckwith
    assigned
    byrneciaran
    on Feb 1, 2021
  8. chingor13
    added 3 commits that reference this issue on Aug 22, 2022

    chore: update github issue templates (#1085) (#594)

    04300df

    chore: update github issue templates (#1085) (#594)

    c472dfa

    chore: update github issue templates (#1085) (#594)

    59b2b27
  9. sofisl
    added 4 commits that reference this issue on Nov 10, 2022

    chore: release 6.0.4 (#594)

    ebb3b2e

    chore: fix .repo-metadata.json (#594)

    79acae7

    chore: run fix instead of lint in synthfile (#594)

    89c79ac

    chore: update github issue templates (#1085) (#594)

    91fb639
  10. 3 remaining items

  11. GautamSharda
    added 2 commits that reference this issue on Jan 14, 2026

    chore: release 2.0.3 (#594)

    5853572

    chore: release 2.0.3 (#594)

    32dfec3
  12. miguelvelezsa
    added a commit that references this issue on Jan 21, 2026

    docs(nodejs): version support policy edits (#1346) (#594)

    bbe43cc
  13. GautamSharda
    added 2 commits that reference this issue on Feb 2, 2026

    chore: new owl bot post processor docker image (#594)

    ccf0089

    chore: new owl bot post processor docker image (#594)

    9822adc
  14. sofisl
    added a commit that references this issue on Feb 4, 2026

    docs(nodejs): version support policy edits (#1346) (#594)

    df0f442
  15. GautamSharda
    added a commit that references this issue on Feb 5, 2026

    chore: release 2.0.3 (#594)

    3c2cbcc
  16. GautamSharda
    added a commit that references this issue on Feb 23, 2026

    chore: release 2.0.3 (#594)

    110d966
  17. sofisl
    added a commit that references this issue on Feb 25, 2026

    docs: add lint/fix example to contributing guide (#594)

    c1e8ad0
  18. GautamSharda
    added 2 commits that reference this issue on Feb 25, 2026

    chore: revert previous node-version template changes in ci.yaml (#594)

    a3d43d8

    chore: release 2.0.3 (#594)

    48b7363
  19. sofisl
    added a commit that references this issue on Feb 26, 2026

    build: patch Windows container, fixing Node 10 (#594)

    4120a79
  20. GautamSharda
    added a commit that references this issue on Mar 12, 2026

    chore: release 3.3.0 (#594)

    799eb2c
  21. sofisl
    added a commit that references this issue on Mar 17, 2026

    chore(main): release 6.2.0 (#594)

    41c048d
  22. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    docs: add lint/fix example to contributing guide (googleapis#594)

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

Metadata

Metadata

Assignees

  • @byrneciaran
    byrneciaran

Labels

api: datastoreIssues related to the Datastore API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    • Datastore FutureNo due date

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.