Datastore Query By Key

Hello,

Excuse me for opening up an issue again, but I've been unable to use the Google Cloud Datastore Resource Query by Key. What is the key supposed to be here? I've tried the generated by GCP key (numeric), tried the name property, path, but nothing seems to fetch the entity. The only way I can correctly find the entity is by running a query by the name, which then returns the correct record. The issue however is that I still need to use the key to save the entity back to datastore, which is something that I cannot get to work.

Is there any documentation on this which can help? The other thread that referenced this did not help me find this information.

Thanks

Hey @BAS! Happy to try to help clarify things for you.

In Retool, the "Query by Key" action requires the "Key path" as input. The Key path is constructed by specifying the path of the kind and the name or ID of the entity. If the entity has a parent(s), you need to include the parent(s) kind(s) and name or ID(s) as well. Here's the general format:

[Kind1, ID_or_Name1, Kind2, ID_or_Name2, ...]

For example, if you have a customers kind and you want to query an entity with the ID 12345 the key path would be:

["customers", 12345]

If your entity has a parent, let's say within the kind region and the name Europe, the key path would look like this:

["region", "Europe", "customers", 12345]

To use the key path in your Retool app, you'd input it in the "Key" field of the "Query by Key" action in your Google Cloud Datastore resource query. Remember that the key path should be in an array format.

Alternatively, you can query an entity by providing a JSON representation of the key. In the "Key" field, enter the JSON representation of the key like this: { "path": [ { "kind": "YourKind", "name": "your_name_property" } ] }

Replace "YourKind" with the Kind of your entity and "your_name_property" with the actual name property value of your entity. After setting the "Key" field properly, you should be able to fetch the entity and also save it back to the datastore using the update and create actions.

If you're still having issues, feel free to share more about your specific datastore structure, and we'll be happy to help further!

Please let us know if you need any further assistance or have any additional questions or concerns!

Hey @victoria,

Thank you so much for the detailed explanation, however I still could not manage to make it work (the first link you mentioned is not working by the way). I uploaded both my schema and the query I am using. I am using Cloud Firestore in Datastore mode in database location us-west1. Let me know if I can provide any more info.


Best regards

So sorry for the delay here, @BAS! Thank you for the callout, I believe I fixed the links now :slight_smile:

This seems to be working for me:

Entities in datastore can be queried by name (String) or an auto id (int).

  • 'Get Entity by Key' only allows for the name to be queried, as the key value is passed as a String
  • 'Delete Entity by Key' only allows for the id to be queried as the key value is parsed as an Int before being passed in
  • 'Query Datastore' Where conditions can only take in strings as inputs, even {{123}}will be parsed as "123"

Does that help at all? Let me know!