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 — How can I create a partial key where the parent uses an ID identifier in Datastore · Issue #567 · googleapis/google-cloud-node

How can I create a partial key where the parent uses an ID identifier in Datastore #567

New issue
Copy link
New issue
Copy link
Closed
Closed
How can I create a partial key where the parent uses an ID identifier in Datastore#567
Copy link
Assignees
stephenplusplus
Labels
api: datastoreIssues related to the Datastore API.type: questionRequest for information or clarification. Not an issue.

Description

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

I know to create a partial key I can write

var key = ds.key(['Entry']);

how can I write a partial key with a parent without specifying name ? For example

var key = ds.key(['Entry', 'Foo', 'Todo']);

creates a partial key with a parent, but the parent key has an identifier name='foot'. How can I state that the parent should use a numeric id (or am I misunderstanding this) ?

Activity

Next
  1. jgeewax commented on May 8, 2015

    @jgeewax
    jgeewax
    on May 8, 2015
    Contributor
    More actions
    var key = dataset.key(['Entry', 1234, 'ChildEntryKind']);

    should do what you want, right?

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

    @byrneciaran
    byrneciaran
    on May 8, 2015
    Author
    More actions

    I was looking for an automatically generated numeric ID. The same way the key will produce something like 5657382461898752 for the ChildEntryKind. I don't want to stick in 1234 for every parent Entry.

  4. jgeewax commented on May 8, 2015

    @jgeewax
    jgeewax
    on May 8, 2015
    Contributor
    More actions

    If you want an auto-generated ID for the parent, you would have to save it first, and then use that auto-generated ID. There is currently no way to create both a parent and a child in a single request where both have auto-generated IDs. That is, you can't make a single request to do the equivalent of this:

    var key = dataset.key(['ParentKind', <auto-generated-id>, 'ChildEntityKind']);

    You can, however, create a child with a non-existent parent, if you choose the name of the parent. That is, if you create the following key, you'll create an entity of Kind ChildEntityKind with an automatically generated ID, which is a child of the non-existent entity {kind: 'ParentKind', keyName: 'parent-entity-key'}:

    var key = dataset.key(['ParentKind', 'parent-entity-key', 'ChildEntityKind']);
  5. stephenplusplus commented on Jun 4, 2015

    @stephenplusplus
    stephenplusplus
    on Jun 4, 2015
    Contributor
    More actions

    I don't believe there's anything else our library can do, since we're limited by:

    There is currently no way to create both a parent and a child in a single request where both have auto-generated IDs.

    @jgeewax is it worth keeping this issue open to track when that feature launches, or is it not something that's being worked on?

  6. jgeewax commented on Jun 4, 2015

    @jgeewax
    jgeewax
    on Jun 4, 2015
    Contributor
    More actions

    Technically, there a few options here:

    1. Pick the key names for both keys. Then you're all set.

    2. Pick a parent key (number or name), and then auto-generate the child key. It's best to try to pick something uniformly distributed (maybe a random base-64 string? or a random number between 1 and ). Then you could always do:

      var key = dataset.key(['ParentKind', <random string or integer>, 'ChildKind']);
    3. Use the allocateIds API method (I don't know if we support that...?) to get a randomly generated ID, and then use that. Then you could do this in a single transaction:

      var firstKey = <allocateIds for a ParentKind key>;
      var childKey = <allocateIds for a ChildKind key, parent = previous key>;
      dataset.runInTransaction(function() {
      <save both entities at once>;
      });

      Obviously this means you have to make 3 separate API calls rather than one, but the important one is in a transaction (if that's what you're looking for).

    Keep in mind that the child can exist without the parent -- so the key ParentKind:1234/ChildKind:5678 doesn't require ParentKind:1234 to exist at all.

    @stephenplusplus: Do we support allocating IDs at all using gcloud-node?

  7. stephenplusplus commented on Jun 4, 2015

    @stephenplusplus
    stephenplusplus
    on Jun 4, 2015
    Contributor
    More actions

    We do: https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.14.0/datastore/dataset?method=allocateIds

  8. stephenplusplus commented on Nov 23, 2015

    @stephenplusplus
    stephenplusplus
    on Nov 23, 2015
    Contributor
    More actions

    I think we've gone over all of the options here, and we currently support solutions 1-3 mentioned above. Please re-open if there's more we can do.

  9. stephenplusplus
    closed this as completedon Nov 23, 2015
  10. JustinBeckwith
    assigned
    stephenplusplus
    on Feb 1, 2021
  11. chingor13
    added 3 commits that reference this issue on Aug 22, 2022

    test: extend timeout for flaky tests (#567)

    95cf712

    test: extend timeout for flaky tests (#567)

    c1730c5

    test: extend timeout for flaky tests (#567)

    28d23b5
  12. sofisl
    added a commit that references this issue on Sep 15, 2022

    build!: update library to use Node 12 (#567)

    e27cbf4
  13. 15 remaining items

  14. sofisl
    added 3 commits that reference this issue on Jan 27, 2026

    fix(deps): update dependency semver to v7 (#567)

    f51adfc

    fix(deps): update dependency semver to v7 (#567)

    ef9809d

    fix(deps): update dependency semver to v7 (#567)

    d640395
  15. miguelvelezsa
    added a commit that references this issue on Jan 28, 2026

    chore(deps): update dependency mocha to v7 (#567)

    c64d932
  16. sofisl
    added 2 commits that reference this issue on Feb 3, 2026

    chore(deps): update dependency typescript to ~3.7.0 (#567)

    102e363

    chore(deps): update dependency mocha to v7 (#567)

    0ecf7f8
  17. GautamSharda
    added a commit that references this issue on Feb 5, 2026

    deps: remove lodash.random and lodash.without (#567)

    10a3447
  18. sofisl
    added a commit that references this issue on Feb 17, 2026

    chore(deps): update dependency mocha to v7 (#567)

    5db6699
  19. GautamSharda
    added a commit that references this issue on Feb 23, 2026

    deps: remove lodash.random and lodash.without (#567)

    cffc19c
  20. sofisl
    added a commit that references this issue on Feb 25, 2026

    build: check broken links in generated docs (#567)

    cae5741
  21. GautamSharda
    added 2 commits that reference this issue on Feb 25, 2026

    fix: limit protobufjs version to one that breaks (#567)

    16d00c2

    deps: remove lodash.random and lodash.without (#567)

    a5b8a1d
  22. GautamSharda
    added 2 commits that reference this issue on Mar 5, 2026

    chore(deps): update dependency typescript to ~3.6.0 (#567)

    e2acab2

    build: remove unused codecov config (#567)

    8883a14
  23. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    build: check broken links in generated docs (googleapis#567)

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

Metadata

Metadata

Assignees

  • @stephenplusplus
    stephenplusplus

Labels

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

Type

No type

Projects

No projects

    Milestone

    No milestone

    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.