这是上下文:
我有一个GCP功能,必须转到数据存储区以获取一些数据才能将数组返回给客户端。
问题:
当我使用有关代码的Datetime过滤器时,我无法实现GCP函数返回数据,但是,当我在GCP数据存储区查询控制台上放置等效查询时,我可以实现回退很多行。 / em>
技术数据:
数据存储区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变量,并在实体变量上返回空数组)
我需要的帮助:
有人能告诉我一个成功的查询案例的例子吗? 使用Datetime过滤器返回实体?
我尝试过dateFrom和dateTo vars的格式:
没有人起作用:(
更新(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);
答案 0 :(得分:0)
在使用客户端库根据日期时间属性对查询结果进行过滤或排序时,应使用相应语言的本机日期时间表示形式,而不是字符串或GQL结构。
特别是对于显然使用的node.js,应使用Date()
对象。这是来自Restrictions on queries的示例:
const query = datastore .createQuery('Task') .filter('created', '>', new Date('1990-01-01T00:00:00z')) .filter('created', '<', new Date('2000-12-31T23:59:59z'));