Skip to content

@google-cloud/datastore 0.5.0 does not return entity keys with query results #250

Description

@stephenplusplus

From @floodfx on November 9, 2016 16:40

Environment details

  • OS: MacOS 10.11.6
  • Node.js version: 6.9.1
  • npm version: 3.10.8
  • google-cloud-node version: 0.43.0
  • @google-cloud/datastore version: 0.5.0

Steps to reproduce

git clone [email protected]:GoogleCloudPlatform/nodejs-docs-samples.git
cd nodejs-docs-samples/datastore

Open quickstart.js
Add code below to end of the file

// query for entities
var q = datastoreClient.createQuery(kind)
q.run((err, entities, nextQuery) => {
  console.log(err, entities, nextQuery)
  for(var i = 0; i < entities.length; i++) {
    var task = entities[i];
    console.log(`Task ${task}: Key${task.key}`);
  }
});

Run

npm install
node quickstart.js

Keys returned with entity results.

Next update package.json to use 0.5.0 of @google-cloud/datastore

Run

node quickstart.js

Keys are "undefined".

Copied from original issue: googleapis/google-cloud-node#1780

Activity

  1. stephenplusplus commented on Nov 9, 2016

    @stephenplusplus
    ContributorAuthor

    From @floodfx on November 9, 2016 16:42

    Note the default version of @google-cloud/datastore for nodejs-docs-samples is "^0.1.1"

  2. stephenplusplus commented on Nov 9, 2016

    @stephenplusplus
    ContributorAuthor

    Thanks for reporting, @floodfx!

    An entity structures its data differently now, not embedding the Key within the object:

    datastore.get(key, function(error, entity) {
      // Before:
      entity.key = Key object
      entity.data = {...data...}
    
      // After:
      entity = {...data...}
      entity[datastore.KEY] = Key object
    });

    See googleapis/google-cloud-node#1768 for more details.

  3. floodfx commented on Nov 9, 2016

    @floodfx

    Thanks @stephenplusplus. appreciate the link. figured I was missing something obvious. Do you know where this is mentioned in the official docs? I spent a lot of time trying to figure this out before trying a different version. Happy to send a PR on docs if that'd be helpful?

  4. stephenplusplus commented on Nov 9, 2016

    @stephenplusplus
    ContributorAuthor

    I'm really sorry about that :( I think we've caught all of the examples in the docs, but they won't update until we cut a new release. If you browse the master docs, you'll see the corrected examples.

    Thank you very much for being patient and offering your help!

  5. jmdobry commented on Nov 9, 2016

    @jmdobry
    Member

    I actually just fixed all of the Datastore samples in this repo to use 0.5.0, the PR is pending review: #249

  6. added 2 commits that reference this issue on Nov 18, 2016
    dbb186a
    ed81bc1
  7. puppetmaster3 commented on Feb 28, 2017

    @puppetmaster3

    Does not work, I tried the new way, and you can't get the key back via query.

  8. czzarr commented on Mar 2, 2017

    @czzarr

    How do you get the key on the front-end without the datastore dependency?

  9. 5 remaining items

  10. added a commit that references this issue on Nov 10, 2022
    5036529
  11. added a commit that references this issue on Nov 16, 2022
  12. added a commit that references this issue on Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🚨This issue needs some love.triage meI really want to be triaged.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions