Lull
Lull

Reputation: 395

Why are IDs for a given kind not unique in Google Cloud Datastore?

In my GAE datastore I have the following kinds:store, order and transaction. One store has several orders, and one order has several transactions. store is parent to order, order is parent to transaction. The ids are generated automatically by the datastore.

In the DB I discovered two different order records with the same id, but with different parents. So it seems that the ids are not unique in themselves - only in combination with their parent? Is this correct?

If so, I always need to query id AND parent in queries?

Thanks, -Louise

Upvotes: 2

Views: 644

Answers (1)

pgiecek
pgiecek

Reputation: 8200

Yes, it is correct. The Datastore will never assign the same numeric ID to two entities with the same parent, or to two root entities (those without a parent).

Each entity in Datastore has a key that uniquely identifies it. The key consists of the following components:

  1. The namespace of the entity, which allows for multitenancy
  2. The kind of the entity, which categorizes it for the purpose of Datastore queries
  3. An identifier for the individual entity, which can be either a key name string or an integer numeric ID
  4. An optional ancestor path locating the entity within Datastore hierarchy

You can find more detail about ancestor paths here.

Upvotes: 4

Related Questions