代码之家  ›  专栏  ›  技术社区  ›  Piyush Bansal

错误消息:InvalidKey:键至少应包含一种类型

  •  0
  • Piyush Bansal  · 技术社区  · 8 年前

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

    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)
    

    我不知道为什么会这样。

    提前谢谢。

    1 回复  |  直到 8 年前
        1
  •  2
  •   Piyush Bansal    8 年前

    “错误消息:InvalidKey:键至少应包含一种类型”

    为了避免这个错误,首先确保[数据仓库.KEY]是可用的。

        2
  •  0
  •   technoY2K    7 年前

    我想对这个答案再加上一点细节。如果在使用数据存储.save方法。实体需要正确的key属性,如下例所示。

    // 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)
    
    推荐文章