Teo Choong Ping
Teo Choong Ping

Reputation: 12808

How to get entity without specifying its ancestor?

I am using Google Cloud node.js gcloud library and trying to get an entity that was saved with ancestor key.

To my surprised, I am not able to get the entity without specifying its ancestor key.

const ds = gcloud.datastore.dataset(config);
 ...
ds.get(key, (err, entity)=>{
   return entity;
});

Upvotes: 3

Views: 198

Answers (1)

Dan McGrath
Dan McGrath

Reputation: 42018

The unique identifier for your entity is the full path, the id/name of the entity is not globally unique.

As an example, let's assume you were modelling a basic file system that has folders and files. Folders are the parent entities and files are the child entities. You might for example have data like:

  • File Entity: name='readme.txt', ancestor=['Folder', 'getting-started']
  • File Entity: name='readme.txt', ancestor=['Folder', 'third-party-libs']

Without specifying the ancestor, the system cannot disambiguate which 'readme.txt' you are trying to reference.

Upvotes: 1

Related Questions