gcloud nodejs datastore: how to create an entity with a parent?

1.4k views Asked by At

How to create an entity with a parent using gcloud, datastore and nodejs?

How to search for all the entities with a given parent?

Something like (this does not work):

var path = [{kind: 'Parent', id: parentId}, {kind: 'Me'}];
var key = ds.key(path);
var entity = {
  key: key,
  data: toDatastore(data, ['description'])
};
ds.save(entity)

Reading the docs I did not find any example of creating an entity with a given parent. I searched (without success) here: https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.19.1

while on the counterpart in python there are some specific proprieties to specify the parent entity: http://googlecloudplatform.github.io/gcloud-python/latest/datastore-keys.html

Please provide an example of code of how create and search for an entity with a parent

1

There are 1 answers

1
Stephen On

I think you just want something like:

var key = ds.key(['Parent', parentId, 'Me']);