I am using glcoud nodejs library for Google datastore (https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.26.0/datastore). I am registering users and as a check I want to only insert if the username (key) is not already registered. I want to only see if the entity already exists, but I don't want to use the get command because it will retrieve the entire entity (the entities are about 400KB in size each). As a result I would only like the most minimal information to return to just acknowledge this entity already exists. I looked into the query option to somehow select only keys, but this does not seem possible? One option is to create an index on just one other field and use projection queries to retrieve only that field and if it returns the object exists. The problem with his though is I have to create an index, which automatically increase my write costs and since this entity will be modified quite often I don't really want to create an index which has no purpose other than to be able to use projection queries on. Is there a solution to this?
Asked
Active
Viewed 252 times
0

Dan McGrath
- 41,220
- 11
- 99
- 130

user2924127
- 6,034
- 16
- 78
- 136
-
Stick with a get, and push much of the 400KB into a child entity, do you need 400KB payload everytime you get the entity other than in this scenario. Any other strategy will increase your write cost, and becuase you don't have things like computed properties, you can't even create this alternate index until you put the entity and get it's key. So put+put (total of 800K now written) to update the alternate index with a key ? or you have another entity just to store the key and then do a projection query on it, but now you have something else to maintain. – Tim Hoffman Dec 13 '15 at 07:48
-
Actually an empty child entity with a known key will be the cheapest. Create the entity, then create an empty child entity with the parent as the ancestor + "child" as the key. Then get that instead of the 400KB entity. It's still a separate entity you have to manage. But get's are always cheaper than queries and it won't have any additional indexes. – Tim Hoffman Dec 13 '15 at 07:54