【问题标题】:GQL nodejs library get(keys) return key name in resultsGQL nodejs 库 get(keys) 在结果中返回键名
【发布时间】:2018-01-09 11:08:02
【问题描述】:

我目前正在使用带有键列表的 NodeJS 数据存储库执行批处理 GQL 查询。

datastore.get(keys).then((results) => {
// Tasks retrieved successfully.
console.log("results", JSON.stringify(results));

res.send()
});

例如,如果我的密钥的 ID 为 1、2、3、4

当得到我的结果时,我想要诸如

之类的东西
   [ {1: {key:value}}, {2: {key:value}},{3: {key:value}},{4: {key:value}}]

而现在我刚刚得到

   [ {key:value}, {key:value},{key:value},{key:value}]

结果全部返回成功,但是ids没有随结果返回。无论如何要检索 id 作为结果的一部分,所以我知道哪些结果与什么 id 相匹配,因为它们看起来不像传入的键的顺序?

【问题讨论】:

    标签: node.js google-cloud-datastore google-cloud-platform gql


    【解决方案1】:

    因此,为了获取密钥,我只需要从我的 results 对象中获取特定实体并获取 [datastore.KEY] 属性

    例如

     let entity = results[0];
     let key = entity[datastore.KEY];
    

    在哪里datastore = require('@google-cloud/datastore')();

    https://github.com/GoogleCloudPlatform/google-cloud-node/issues/1724

    【讨论】:

      猜你喜欢
      • 2019-06-18
      • 2015-04-23
      • 1970-01-01
      • 1970-01-01
      • 2022-12-29
      • 2020-06-23
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多