Google App Engine Datastore: creating and using a key without an entity
I have a kind of weird question to all of you who are Google Datastore expert. I've been studying the code of a working Google App Engine app. I found these lines of codes which make me confused. guestbook_key = ndb.Key(Greeting, DEFAULT_GUESTBOOK_NAME) mykey = ndb.Key( Greeting, # kind str(i+1), # id parent=guestbook_key # parent ) g = Greeting(key=mykey)` My question is: Is it possible using, as a parent, the key of an entity which doesn't exist? I say it because no entity with key "guestbook_key" has been created (i searched in the entire code but i didn't find anything) Is it created only for giving a common root to entities without creating an entity root?
Yes. From Using the ancestor path in the key (emphasis mine): ndb.Key('Account', 'sandy#example.com', 'Message', 123, 'Revision', '1') ... In the sample, ('Account', 'sandy#foo.com'), ('Message', 123), and ('Revision', '1') are all examples of kind-identifier pairs. Notice that Message is not a model class; it is used only as a way to group revisions, not to store data. ... You can use the named parameter parent to designate any entity in the ancestor path directly. All of the following notations represent the same key: ndb.Key('Account', 'sandy#example.com', 'Message', 123, 'Revision', '1') ndb.Key('Revision', '1', parent=ndb.Key( 'Account', 'sandy#example.com', 'Message', 123)) ndb.Key('Revision', '1', parent=ndb.Key( 'Message', 123, parent=ndb.Key('Account', 'sandy#example.com'))) In the quoted example above the Message entity keys are used as ancestor/parent keys for Revision entities without the Message entities actually existing. Another such example, this time showing the root (common ancestor) of an entire entity group not actually existing: What would be the purpose of putting all datastore entities in a single group?
Key is just an object in your program's memory even before anything is written to the datastore. When you write an entity to the datastore, you will need to supply the key (complete, or incompletely if you want auto ID), and the data itself.
Is the Cloud Datastore Emulator a dropin replacement for the local Datastore that is part of the Eclipse AppEngine plugin?
How do I create/use a GWT Client for AppEngine Endpoints?
Query by multiple doc_ids in Google App Engine Search API
Appengine ndb - Transactions can report failure but succeed
ImportError: No module named _ctypes running Python Flask tutorial for Google App Engine on Windows
Gcloud custom domain
Not getting all labels with Adwords Python client
Standard for Google Cloud and AWS Setup for multiple instances
GAE custom domain wildcard subdomain issues
Cron per Service/Module (AppEngine)
How do we parse and generate App Engine URL-Safe Datastore Keys in the Google Cloud API?
Google App Engine: How to create HTTPS endpoints with flexible environment?
Deployed Google Endpoints Quickstart app giving error message when i request url?
Google Cloud SDK vs Google Cloud Client Libraries
when does dispatch.xml get updated?
How do I stop this Google cloude Instances billing?