0

I am using @google-cloud/datastore to save data in my entity.I have created the entity with custom key name = id. How can I have a custom UUID as the key of the entity?

ds.save({
    id: <uuid>,
    data: Log
}).then(function () {
    console.log(entities.map(fromDatastore));
});

1 Answer 1

1
const dsKey = ds.key({
    namespace : namespace,// optional
    path      : ([kindName, id]) 
  })

The key can be generated like this. The namespace is optional, if not provided the default namespace will be used. In the path kindname should be provided(if there is a parent kind for the provided kind, the path array value should begin from the root parent name and id) and the id can be any id you assign. If the id is not provided, datastore will generate a random id and assign it to the entity you inserted.

If you meant that you wanted the UUId as the complete key, that is not possible.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.