0
votes

I've just started to learn more about the project I'm working on. Turns out it uses GCP datastore. I went to the entity management interface. I created a new namespace and added an entity into it. In our typescript backend, I wrote a function that mimiced the example for node.js. However, I can't find out how to query the new namespace, or any namespace for that matter (besides the default namespace). I found some documentation that mentions namespaces, but none of it seemed to apply to my case. Does anybody know how I can query a particular namespace in the datastore?

async function listReviews( brand, sku ) {

  const query = datastore.createQuery('Review').order('createdOn');

  console.log('query: ', query);

  const [reviews] = await datastore.runQuery(query);
  
  for (const review of reviews) {
    const reviewKey = review[datastore.KEY];
    console.log(reviewKey.id, review);
  }
}
1
I just discovered if I remove the const qualifier on the query variable, i can modify the .namespace property of the variable and set it to whatever I want. I got it to properly query the namespace I want with the entity kind I want, along with the data of each entity of those kinds. I'm betting there's a better way to do this, but I haven't found it yet. - user8694-03

1 Answers

1
votes

Turns out the call to createQuery takes an optional leading paramter... ie:

datastore.createQuery(namespace, kind)

default value of namespace must be [default] namespace.