Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Help Needed: Issues with Google Cloud Datastore 'NOT_FOUND' Error in Node.js

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.

Context:

  1. API Availability: Both Cloud Datastore API and Cloud Firestore API are enabled in my project.
  2. Service Account Permissions: The service account is active and has the Cloud Datastore User role. There are no other overriding policies, and it has been impersonated correctly.
  3. Network and Quota: Quota usage is at 0%, and there are no apparent network issues.
  4. Service Account Authentication: I've set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the correct path of the service account key file.

Code Snippet:

 

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 Message:

 

Error: 5 NOT_FOUND: 
    at callErrorFromStatus (D:\OTP-Verification\node_modules\@grpc\grpc-js\build\src\call.js:31:19)
    ...

 

Troubleshooting Steps Taken:

  1. Checked API availability - both APIs are enabled.
  2. Verified service account permissions - service account has the correct roles.
  3. Ensured correct project ID and service account authentication.
  4. No recent changes or previous working setup - this is the first attempt with this setup.

Additional Context:

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.

0 2 848
2 REPLIES 2

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');

 

    ......NoCommandLine ......
https://nocommandline.com
        Analytics & GUI for 
App Engine & Datastore Emulator

I have tried to:

  1. Run Local Datastore Emulator and the code is working: The code is working perfectly for local emulator
  2. Impersonate Service Account using this code:

 

 

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