I would be nice if entity ids were globally unique within an application

23 views
Skip to first unread message

Alexander Dementsov

unread,
Aug 12, 2014, 8:52:20 PM8/12/14
to appengine-...@googlegroups.com
From docs I see two mutually contradictory statements about uniqueness of entity ids:

"Each entity is identified by a key, unique within the application's Datastore."

"If an application picks some IDs "by hand" and they're numeric and the application lets the Datastore generate some IDs automatically, the Datastore might choose some IDs that the application already used."


Why not make the entity ids globally unique? When I use parent/child relation I can't reference child just by using entity id. I always have to use combination of parent and child id.

Kaan Soral

unread,
Aug 13, 2014, 2:49:09 PM8/13/14
to appengine-...@googlegroups.com
Didn't get the initial issue, however +1 on the parent/child key issue, I never use parent's for this reason
I'm guessing there might be a logical/technical/performance reason for things being the way they are, also considering ndb was a refined version of db, they probably had chance to make these kinds of improvements too (or not, since ndb is probably at a higher level than the low-level datastore stuff)
(also, offtopic, lol @ the title :)

Patrick Costello

unread,
Aug 13, 2014, 3:17:59 PM8/13/14
to appengine-...@googlegroups.com
The difference is that Keys are unique within an application but IDs are only unique with an entity group. Anywhere you need a key I would recommend passing around the serialized version of the key instead of just the ID. Then, whenever you need the key you already have the parent.

Using a parent is incredibly important for providing strong consistency in your application. I would recommend reading this article if you're interested in the trade offs between using a parent (entity groups) and not. 

Alexander Dementsov

unread,
Aug 13, 2014, 6:32:57 PM8/13/14
to appengine-...@googlegroups.com
I would prefer to have a simple serialization (some string or ID) to uniquely identify the key instead bringing up the whole entity hierarchy to recreate the key. This hierarchy can change over time. MongoDB has "most likely" unique ObjectID accross all collections (http://docs.mongodb.org/manual/reference/object-id/#core-object-id-class).


--
You received this message because you are subscribed to a topic in the Google Groups "appengine-ndb-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/appengine-ndb-discuss/bxkva_utXZM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to appengine-ndb-di...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Patrick Costello

unread,
Aug 13, 2014, 7:20:47 PM8/13/14
to appengine-...@googlegroups.com
If you need to pass around a string representation of a key, you can use the urlsafe method: https://developers.google.com/appengine/docs/python/ndb/keyclass#Key_urlsafe. The hierarchy of an individual key can never change over time -- once an entity is created its key is locked in. 

If you wanted, you could also generate a random unique string id and do this manually.

To unsubscribe from this group and all its topics, send an email to appengine-ndb-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages