This and other similar questions often arise when it comes to moving from a traditional RDB to a data warehouse like BigTable, such as App Engine.
It is often useful to discuss why the data warehouse does not support unique keys, as it informs the thinking you should be in when you think about your data storage schemes. The reason unique constraints are not available is because it significantly limits scalability. As you said, enforcing a constraint means checking all other objects for this property. Regardless of whether you do this manually in your code, or whether the data warehouse is automatically behind the scenes, this should happen anyway, which means lower performance. Some optimizations can be made, but it should still happen anyway.
The answer to your question: really think about why you need this unique limitation.
Secondly, remember that keys exist in the data store and are a great way to provide a simple unique constraint.
my_user = MyUser(key_name=users.get_current_user().email()) my_user.put()
This ensures that MyUser will never be created with this email, and you can also quickly get MyUser with this email address:
my_user = MyUser.get(users.get_current_user().email())
In the python runtime, you can also:
my_user = MyUser.get_or_create(key_name=users.get_current_user().email())
What will insert or retrieve the user with this email.
Anything more complicated will not be scalable. So really think about whether you need this property to be globally unique, or if there are ways to eliminate the need for this unique restriction. Often you will find with some small workarounds that you do not need so that the property is unique in the end.
Jason hall
source share