每次运行datastore.runQuery时都会出错:必须设置Query.query和Query.gql_query字段之一 [英] Error every time I run datastore.runQuery: one of fields Query.query and Query.gql_query must be set

本文介绍了每次运行datastore.runQuery时都会出错:必须设置Query.query和Query.gql_query字段之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用google-api-nodejs-client对我的Google Cloud数据存储区执行简单查询。我想查询所有匹配给定种类的实体。当我使用立即试用工具运行此查询时它工作正常:

 请求

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

{
query:{
kinds:[
{
name:订户
}
]
}
}

回应

200 OK


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

我可以使用我的身份验证证书,创建一个事务,例如, tc。所以我知道这不是一个认证问题。



下面是我试图在Node中运行的代码:

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

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

  {[错误:其中一个字段Query.query和Query.gql_query必须设置] 
代码:400,
错误:
[{domain:'global',
reason:'INVALID_ARGUMENT',
message:'其中一个字段Query.query和Query.gql_query必须设置'}]}

这没有意义,因为我已经指定了查询 code>字段。我尝试了各种各样的事情:使用<$ c删除 datasetId (产生关于需要 datasetId 的错误) $ c> gql_query 改为(同样的错误),将 datasetId 封装在一个事务中,并在 readOptions

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



谢谢!

解决方案

我在其他StackOverflow问题,但您的请求应包含在资源部分中:

  this.datastore.runQuery({
datasetId:'healthier-staging',
resource:{
query:{
类:[{name:'Subscriber'}]
},
},
},(函数(err,result){
if(err){
console.error(err);
返回;
}
})。bind(this));


I'm trying to run a simple query against my Google Cloud datastore using google-api-nodejs-client. I want to query for all entities matching a given kind. When I run this query using the "Try it now" tool it works fine:

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": {
...

I'm able to authenticate using my credentials, create a transaction, etc. so I know it's not an authentication issue.

Here's the code I'm trying to run in Node:

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

When I try to run the same query using the Node module, I get this error:

{ [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' } ] }

This doesn't make sense, since I've specified the query field. I've tried all sorts of things: removing datasetId (produces an error about needing datasetId), using gql_query instead (same error), encapsulating the datasetId inside a transaction and passing that along inside readOptions, etc.

Is this a bug or am I doing something silly?

Thanks!

解决方案

I mentioned this on your other StackOverflow question, but your request should be included in the resource section:

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

这篇关于每次运行datastore.runQuery时都会出错:必须设置Query.query和Query.gql_query字段之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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