gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:44:01 25 4
gpt4 key购买 nike

我正在尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com