【发布时间】:2019-04-09 05:05:03
【问题描述】:
这是上下文:
我有一个 GCP 函数,它必须去 Datastore 获取一些数据才能将数组返回给客户端。
问题:
当我对我的代码使用日期时间过滤器时,我无法实现 GCP 函数返回数据,但是,当我在 GCP 数据存储查询控制台上放置等效查询时,我可以实现返回很多行。
技术数据:
数据存储区 GQL:
select * from KIND where recordDate >= DATETIME ("2018-10-10T10:10:00.000000+03:00") and recordDate <= DATETIME ("2018-10-11T10:10:00.999999+03:00")
(适用于 GCP 数据存储控制台)
GCP 功能代码:
query = datastore.createQuery(kind).filter('recordDate','>=',dateFrom).filter('recordDate','<=',dateTo);
console.log(query);
datastore.runQuery(query, (err,entities) => {
console.log(err);
console.log(entities);
});
(它 runQuery()... 总是返回 null 作为 err 变量并在实体变量上返回一个 void 数组)
我需要的帮助:
谁能告诉我一个成功的查询示例 使用日期时间过滤器返回实体?
我尝试了关于 dateFrom 和 dateTo vars 格式的方法:
- 日期时间(“2018-10-10T10:10:00.000000+03:00”)
- 日期时间(“2018-10-10 10:10:00”)
- “2018-10-10T10:10:00.000000+03:00”
- '2018-10-10T10:10:00.000000+03:00'
- 日期时间(“2018-10-10”)
- “2018-10-10”
- 日期(“2018-10-10”)
- 日期('2018-10-10')
- 日期时间 (2018-10-10T10:10:00.000000+03:00)
没有人工作:(
更新(2018-11-19):
我在 runQuery 之前打印了查询,我得到了这个: (我把一些点放在安全的敏感数据上)
{
"textPayload": "Query {\n scope: \n Datastore {\n clients_: Map {},\n datastore: [Circular],\n namespace: undefined,\n projectId: '................',\n defaultBaseUrl_: 'datastore.googleapis.com',\n baseUrl_: 'datastore.googleapis.com',\n options: \n { libName: 'gccl',\n libVersion: '2.0.0',\n scopes: [Array],\n servicePath: 'datastore.googleapis.com',\n port: 443,\n projectId: 'c..........' },\n auth: \n GoogleAuth {\n checkIsGCE: undefined,\n jsonContent: null,\n cachedCredential: null,\n _cachedProjectId: 'c..........',\n keyFilename: undefined,\n scopes: [Array] } },\n namespace: null,\n kinds: [ '....KIND......' ],\n filters: \n [ { name: 'recordDate', op: '>', val: 2018-10-10T00:00:00.000Z },\n { name: 'recordDate', op: '<', val: 2018-10-12T23:59:59.000Z } ],\n orders: [],\n groupByVal: [],\n selectVal: [],\n startVal: null,\n endVal: null,\n limitVal: 20,\n offsetVal: -1 }",
"insertId": "............................098...",
"resource": {
"type": "cloud_function",
"labels": {
"region": "us-central1",
"function_name": "...................-get-search",
"project_id": "............."
}
},
"timestamp": "2018-11-19T21:19:46.737Z",
"severity": "INFO",
"labels": {
"execution_id": "792s.....lp"
},
"logName": "projects/......./logs/cloudfunctions.googleapis.com%2Fcloud-functions",
"trace": "projects/........../traces/4a457.......",
"receiveTimestamp": "2018-11-19T21:19:52.852569373Z"
}
功能代码是:
query = datastore.createQuery(kind).filter('recordDate','>',new Date(dateFrom)).filter('recordDate','<',new Date(dateTo)).limit(20);
console.log(query);
var test = datastore.runQuery(query, (err,entities) => {
console.log(err);
console.log(entities);
entities.forEach(entity => {
console.log(entity);
});
return{
entities:entities,
err:err
};
});
console.log(test);
【问题讨论】:
标签: datetime google-cloud-platform google-cloud-datastore google-cloud-functions gql