Node.js中的Google datastore.lookup不会返回任何结果 [英] Google datastore.lookup in Node.js returns no results

本文介绍了Node.js中的Google datastore.lookup不会返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过 google-api-nodejs-client JS插件对我的Google数据存储数据进行简单的查找。当我使用 Google的立即尝试来运行此查找时,工具,它工作正常:

I'm trying to run a simple lookup against my Google datastore data via the google-api-nodejs-client JS plugin. When I run this lookup using Google's "try it now" tool, it works fine:

Request

POST https://www.googleapis.com/datastore/v1beta2/datasets/healthier-staging/lookup?key={YOUR_API_KEY}

{
 "keys": [
  {
   "path": [
    {
     "kind": "Subscriber",
     "name": "+1215XXXXXXX"
    }
   ]
  }
 ]
}

Response

200 OK

{
 "found": [
  {
   "entity": {
    "key": {
     "partitionId": {
      "datasetId": "s~healthier-staging"
     },
     "path": [
      {
       "kind": "Subscriber",
       "name": "+1215XXXXXXX"
      }
     ]
    },
    "properties": {
     "phone": {
...

但是,当我在Node.js中运行完全相同的查询时,我没有结果 - 没有错误,但也没有结果。我能够进行身份验证,连接到数据存储,创建事务等,因此它似乎不是身份验证问题。下面是我正在运行的Node代码:

However, when I run exactly the same query in Node.js, I get no results--no error, but also no results. I'm able to authenticate, connect to the datastore, create a transaction, etc. so it doesn't appear to be an authentication issue. Here's the Node code I'm running:

this.datastore.lookup({
    datasetId : 'healthier-staging',
    keys: [{ path: [{ kind: 'Subscriber', name: '+1215XXXXXXX' }] }]
},
    (function(err, result) {
        if (err) {
            console.error(err);
            return;
        }
        console.log(result);
}).bind(this));

而控制台的输出是:

And the console output is:

{ found: [], missing: [], deferred: [] }

注意:这与我在,我试图使用 code> runQuery 而不是 lookup ,但我面对的问题是不同的。

Note: this is related to the issue I reported in Error every time I run datastore.runQuery: one of fields Query.query and Query.gql_query must be set where I am trying to read the same data using runQuery instead of lookup, but the issue I'm facing is different.

谢谢。

推荐答案

这些键应该是后期有效载荷的一部分:

The keys should be part of the post payload:

this.datastore.lookup({
    datasetId : 'healthier-staging',
    resource: {
        keys: [{ path: [{ kind: 'Subscriber', name: '+1215XXXXXXX' }] }]
    }
},
    (function(err, result) {
        if (err) {
            console.error(err);
            return;
        }
        console.log(result);
}).bind(this));

您可以找到API 这里

这篇关于Node.js中的Google datastore.lookup不会返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆