-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datastore Key is not returned on runQuery with new entity change #1768
Comments
Sorry about that. It looks like we haven't done a release since we updated the docs. We left behind many examples that were invalidated when we switched from the nested object. The way to get the key is by using a special property (a var key = entity[datastore.KEY] Sorry for the confusion, we should have a new release out soon so the docs can be refreshed. |
Can I ask what the benefit of changing |
Does not work, I tried the new way, and you can't get the key back via query. |
The key is undefined for me when I used I am using "@google-cloud/datastore": "1.0.0".
Update (there's no problem)
To illustrate: |
Thanks for writing that up. Here are all the ways to use // Callback with a single key
datastore.get(key1, function(err, entity) {
// entity = { key1's data object }
})
// Callback with multiple keys
datastore.get([key1, key2], function(err, entities) {
// entities = [
// { key1's data object },
// { key2's data object }
// ]
})
// Promise with a single key
datastore.get(key1)
.then(function(data) {
var entity = data[0]
// entity = { key1's data object }
})
// Promise with multiple keys
datastore.get([key1, key2])
.then(function(data) {
var entities = data[0]
// entities = [
// { key1's data object },
// { key2's data object }
// ]
}) The historyBefore we supported callbacks, we wanted Our callbacks have a consistent signature, where possible:
Because of that third argument, method()
.then(function(data) {
// an array:
data = [ thingOrThingsYouWanted, apiResponse ]
// an object:
data = {
thingOrThingsYouWanted: thingOrThingsYouWanted,
apiResponse: apiResponse
}
}) The array was decided to be the best option. Because of that, |
Stephen, many thanks for the detailed explanation and sharing about the history. Now I understand why there is an array inside an array for the promise call. I'll comment on #2167. |
@mrkevinze You saved my life! I don't even remember how I got to this result, but I am glad I did! I am still trying to understand the mechanics of Google Datastore. |
How do I get the keys of the entities if I use a query? I have a function like this I tried to get the results key as above. But the resulting key is an object and it doesn't have my datastore key it has something like this Can anyone help me with this? |
@melvinmeshach-full greetings! Would you mind opening a new issue? It will make finding and answering much easier :) |
Sure will open a new one.
|
took an hour to find out how to get the key from an entity using this odd syntax. Node.js docs for Datastore are quite frustrating. |
4 years later and this issue thread is the best documentation I could find explaining how to access the key from a queried entity result. You know, only useful if you ever need to do something arbitrary like update an existing entity or something. |
With the new change to Datastore where runQuery returns entities instead of the old nested json object, there seems to be no way to retrieve the key along with the entity.
I'm currently returning a list of 40 entities at a time with no way to save the ID's with the entities. I'm mapping into a GraphQL server where the ID's are used as part of the cursors.
The documentation has no information on this. Is there an option or am I missing something?
Thanks
The text was updated successfully, but these errors were encountered: