How can I get the key of an entity returned by a query?
I tried to access it like the normal data, but when I print the entity itself there is no key. Is there even a way to do so?
Thank you in advance for your help.
How can I get the key of an entity returned by a query?
I tried to access it like the normal data, but when I print the entity itself there is no key. Is there even a way to do so?
Thank you in advance for your help.
According to the documentation,
datastore.runQuery
returns a entity objects, with the propertiesdata
andkey
. You are interested inkey
.So, for example using the first entity, you would access the key like this:
Since version 0.5.0 of the @google-cloud/datastore v0.5.0 the key is now accesible by a Symbol.
You could also use the gstore-node library (https://github.com/sebelga/gstore-node) and then you would access it directly by entity.entityKey