【问题标题】:Error Message : InvalidKey: A key should contain at least a kind错误消息:InvalidKey:密钥应至少包含一种
【发布时间】:2018-08-29 06:41:15
【问题描述】:

我在尝试更新谷歌云数据存储中的实体时遇到以下错误:

InvalidKey: A key should contain at least a kind.
    at keyToKeyProto (/Volumes/Drive B/dev/zapi/node_modules/@google-cloud/datastore/src/entity.js:696:11)
    at Array.map (<anonymous>)
    at DatastoreRequest.createReadStream (/Volumes/Drive B/dev/zapi/node_modules/@google-cloud/datastore/src/request.js:226:23)
    at DatastoreRequest.get (/Volumes/Drive B/dev/zapi/node_modules/@google-cloud/datastore/src/request.js:461:8)
    at /Volumes/Drive B/dev/zapi/node_modules/@google-cloud/common/build/src/util.js:681:32
    at new Promise (<anonymous>)
    at Datastore.wrapper [as get] (/Volumes/Drive B/dev/zapi/node_modules/@google-cloud/common/build/src/util.js:662:20)
    at fetchEntity (/Volumes/Drive B/dev/zapi/node_modules/gstore-node/lib/model.js:204:36)
    at Function.get (/Volumes/Drive B/dev/zapi/node_modules/gstore-node/lib/model.js:174:16)
    at Promise (/Volumes/Drive B/dev/zapi/node_modules/gstore-node/lib/utils.js:39:35)
    at new Promise (<anonymous>)
    at Function.wrapper (/Volumes/Drive B/dev/zapi/node_modules/gstore-node/lib/utils.js:27:16)
    at resolve (/Volumes/Drive B/dev/zapi/graphql/mutations/user/linkConsult.js:101:44)

我不知道为什么会这样。

提前致谢。

【问题讨论】:

  • 用于构造密钥路径的(种类、ID/名称)对。一种匹配正则表达式 .* 是保留/只读的。不能是“”。Learn more

标签: node.js google-cloud-datastore


【解决方案1】:

当你试图访问 key 并且 key 不可用时,没有可用的数据,它会给出错误

“错误信息:InvalidKey:一个键应该至少包含一种”

为避免此错误,首先确保 [datastrore.KEY] 可用。

谢谢

【讨论】:

    【解决方案2】:

    我想在这个答案中添加更多细节。如果您在使用 datastore.save 方法时遇到此错误,这里有一些其他有用的点可供调查。实体需要正确的键属性,如下例所示。

    // remember to use the key method on the google data store instance
    const entity = {
      key: dataStore.key('Name of your Kind') // this is Kind property you see on the GCP dashboard,
      data: {
        example: 'this is an example',
        ...
      }
    };
    
    // then save the entity
    const dbResult = await dataStore.save(entity)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 2014-10-25
      • 1970-01-01
      • 2014-02-07
      • 2014-05-31
      • 2021-01-22
      • 2021-12-25
      相关资源
      最近更新 更多