javascript - 每次运行 datastore.runQuery : one of fields Query. 查询时都会出错,并且必须设置 Query.gql_query

标签 javascript node.js google-app-engine google-cloud-datastore google-api-nodejs-client

我正在尝试使用 google-api-nodejs-client 对我的 Google Cloud 数据存储区运行简单查询。我想查询与给定类型匹配的所有实体。当我使用 the "Try it now" tool 运行此查询时它工作正常:

Request

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

{
 "query": {
  "kinds": [
   {
    "name": "Subscriber"
   }
  ]
 }
}

Response

200 OK

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

我能够使用我的凭据进行身份验证、创建交易等,因此我知道这不是身份验证问题。

这是我尝试在 Node 中运行的代码:

this.datastore.runQuery({
    datasetId: 'healthier-staging',
    query: {
        kinds: [{name: 'Subscriber'}]
    },
}, (function(err, result) {
    if (err) {
        console.error(err);
        return;
    }
}).bind(this));

当我尝试使用 Node 模块运行相同的查询时,出现此错误:

{ [Error: one of fields Query.query and Query.gql_query must be set]
  code: 400,
  errors: 
   [ { domain: 'global',
       reason: 'INVALID_ARGUMENT',
       message: 'one of fields Query.query and Query.gql_query must be set' } ] }

这没有意义,因为我已经指定了 query 字段。我尝试过各种方法:删除 datasetId (产生需要 datasetId 的错误),使用 gql_query 代替(相同的错误),封装事务内的 datasetId 并将其传递到 readOptions 等中。

这是一个错误还是我做了一些愚蠢的事情?

谢谢!

最佳答案

我在你的 other StackOverflow question 上提到过这一点,但您的请求应包含在资源部分中:

this.datastore.runQuery({
    datasetId: 'healthier-staging',
    resource: {
        query: {
            kinds: [{name: 'Subscriber'}]
        },
    },
}, (function(err, result) {
    if (err) {
        console.error(err);
        return;
    }
}).bind(this));

关于javascript - 每次运行 datastore.runQuery : one of fields Query. 查询时都会出错,并且必须设置 Query.gql_query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31094523/

相关文章:

javascript - 删除隐藏字段后 Django 中发生 CSRF 错误

javascript - redis-server 离线导致 Node 崩溃

python - 为什么会失败? (谷歌应用程序引擎数据存储,Python)

python - 动态过滤数据存储中的应用程序引擎数据

java.lang.OutOfMemory错误: Java heap space - blobstoreService

javascript - 是否可以通过 ajax 提交表单的一部分和表单 'normally' 的另一部分?

javascript - 使用javascript从字符串中获取变量内容

javascript - 将回调函数作为参数返回 false

javascript - 使用 discord.js 加入 discord 服务器时的欢迎消息

node.js - 如何在特定视频秒向视频文件添加背景音乐?在 Node 流利-ffmpeg中