代码之家  ›  专栏  ›  技术社区  ›  KiKu

云数据存储插入和升级问题

  •  0
  • KiKu  · 技术社区  · 6 年前

    在实体键下插入附加属性时,我遇到了一个奇怪的问题。

    enter image description here

    server.post('/submit', (req, res,) => {
    
    
        const OutTime  = new Date();
    
     const key = datastore.key([VData, 5717023518621696])
     const entity = {
       key:key,
       method: 'insert',
       data: { content: OutTime },
     }
    
     datastore.insert(entity).then(() => {
      // Task inserted successfully.
    });
    // [END datastore_upsert]
    
    });

    https://cloud.google.com/datastore/docs/concepts/entities

    1 回复  |  直到 6 年前
        1
  •  2
  •   Dan Cornilescu    6 年前

    这是意料之中的,您不能只添加/修改现有实体的属性-整个实体需要重新编写。所以你需要 get update / upsert 它返回到数据存储。

    Updating an entity 在您引用的文档中(强调我的文档):

    . 如果实体不存在,则 更新将失败。如果要更新或创建实体,请使用 更新插入 如前所述。使用 transaction 得到 更新 单个原子中的操作

    Creating an entity (我的重点):

    您可以使用将实体保存到云数据存储 更新插入 ( 哪一个 云中数据存储)