Hi GCP Community,
I'm encountering an issue with Google Cloud Datastore while trying to save an entity using Node.js. Despite following the documentation and setting up the necessary configurations, I'm consistently hitting a 5 NOT_FOUND error when trying to save data. This is my first time working with this library, and I'm feeling a bit lost. I would greatly appreciate any insights or guidance you can offer.
const {Datastore} = require('@google-cloud/datastore');
// Creates a client
const datastore = new Datastore({
projectId: 'your-project-id', // Replace with your actual project ID
});
async function quickstart() {
try {
const kind = 'your-kind';
const name = 'your-entity-name';
const taskKey = datastore.key([kind, name]);
console.log("Key: ", taskKey);
const task = {
key: taskKey,
data: {
OTP: 123456,
expireAt: new Date(Date.now() + 600000),
},
};
console.log("Task: ", task);
await datastore.save(task);
console.log('Entity saved successfully.');
} catch (err) {
console.error('Error saving entity:', err);
}
}
quickstart();
Error: 5 NOT_FOUND:
at callErrorFromStatus (D:\OTP-Verification\node_modules\@grpc\grpc-js\build\src\call.js:31:19)
...
This issue has been quite frustrating as I'm eager to make progress on this project but keep hitting this roadblock. Any advice, troubleshooting tips, or similar experiences would be incredibly helpful. I would also appreciate suggestions for any additional steps I might be missing or if there's a more suitable role I should consider.
Is your code running on your dev environment (e.g. your local machine)? If so, are you sure the library was installed correctly? Do you have the datastore emulator running (if you aren't running the datastore emulator, then your code will try to access your production environment and this means you must have the necessary Application Default Credentials setup).
If none of the above is the issue, then try creating an incomplete key (i.e. you specify only the Kind so that datastore will assign the id) e.g.
const taskKey = datastore.key('Tasks');
I have tried to:
gcloud auth application-default login --impersonate-service-account <service-account@email>
Code is still giving error when it is being used with GCP instance of Datastore
Why is this error when it is being used with GCP instance, when there is no issue for local emulator