Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 574
allergique Avatar asked Aug 21 '15 10:08

allergique


1 Answers

I think you just want something like:

var key = ds.key(['Parent', parentId, 'Me']);
  • Key docs
like image 83
Stephen Avatar answered Nov 15 '22 06:11

Stephen