Hi,
I understand your use case and I think the best way to accomplish that would be something like suggested in this StackOverflow <https://stackoverflow.com/questions/51407626/google-cloud-datastore-unique-autogenerated-ids> post and set up your own GUIDs. I hope that helps! On Friday, June 14, 2019 at 10:53:30 PM UTC-4, NP wrote: > > Thanks for your response. And yes, I was referring to the numeric id. > > In case it wasn't clear from my post, I actually want the ids to be > unique. I was just trying to confirm that it is. > > The reason I would prefer the ids are unique is because I have seeded data > which all my users can use. The users can then in turn create entities for > their application which are saved with a namespace for the user. Since each > user basically has access to 2 namespaces (the default or blank namespace > which contains my seeded data and the namespace for their app), I would > like to search for entities by just their numeric ids. If I find the > record, I then check the namespace associated with the corresponding key. > For this to work, the ids need to be unique across all namespaces. > > > > On Friday, June 14, 2019 at 7:06:48 PM UTC-7, Harmit Rishi (Cloud Platform > Support) wrote: >> >> In order to effectively address your question, I would like to take a >> moment and explain the characteristics of a Entity >> <https://cloud.google.com/datastore/docs/concepts/entities>. Each entity >> within Datastore has a key that uniquely identifies it. The key (as you >> provided) consists of the following components: >> >> 1. Namespace of the entity >> 2. The kind >> <https://cloud.google.com/datastore/docs/concepts/entities#kinds_and_identifiers> >> >> of entity (categorized for queries) >> 3. An Identifier >> <https://cloud.google.com/datastore/docs/concepts/entities#kinds_and_identifiers> >> >> for the individual entity (can be a key name string or a integer numeric >> id.) >> >> I will be assuming that you are referring to the integer numeric id for >> your question. >> >> As far as having two of the same numeric ID's goes, indeed it is possible >> and this can be done by having your application assign their own numeric >> IDs manually to the entitles being created. However, as indicated in the >> documentation here >> <https://cloud.google.com/datastore/docs/concepts/entities#kinds_and_identifiers>, >> >> "there is nothing to prevent a Datastore mode database from assigning one >> of your manual numeric IDs to another entity". You will have to implement >> the *allocateids() >> <https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/datastore/DatastoreService#allocateIds-java.lang.String-long->*method >> >> within your application which will allow you to obtain a block of IDs in >> order to avoid the conflict mentioned above. >> >> Also, since you mentioned that "Datastore is the one automatically >> generating the ids", the documentation found here >> <https://cloud.google.com/datastore/docs/concepts/entities#kinds_and_identifiers> >> states >> that the "automatic ID generator will keep track of IDs that have been >> allocated" and that Datastore "will avoid reusing them for another entity". >> >> Therefore to sum it all up. Yes, you can achieve the goal you want. >> However, it would be a good idea to implement the best practices for it as >> well such as: manually assigning Ids with implementing *allocateids() >> <https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/datastore/DatastoreService#allocateIds-java.lang.String-long->* >> . >> >> I hope this helps! >> >> -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/8b2ce549-ab1e-40c9-93b3-126d2bc17a5a%40googlegroups.com.
