【问题标题】:How to get entity without specifying its ancestor?如何在不指定其祖先的情况下获取实体?
【发布时间】:2017-05-10 04:35:59
【问题描述】:

我正在使用 Google Cloud node.js gcloud 库并尝试获取使用祖先密钥保存的实体。

令我惊讶的是,我无法在不指定其祖先键的情况下获取实体。

const ds = gcloud.datastore.dataset(config);
 ...
ds.get(key, (err, entity)=>{
   return entity;
});

【问题讨论】:

    标签: node.js google-cloud-datastore google-cloud-platform data-modeling


    【解决方案1】:

    您的实体的唯一标识符是完整路径,实体的 ID/名称不是全局唯一的。

    举个例子,假设您正在建模一个包含文件夹和文件的基本文件系统。文件夹是父实体,文件是子实体。例如,您可能有如下数据:

    • 文件实体:name='readme.txt',祖先=['Folder','getting-started']
    • 文件实体:name='readme.txt',祖先=['Folder','third-party-libs']

    如果不指定祖先,系统无法消除您尝试引用的“readme.txt”的歧义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-30
      • 2013-12-02
      • 1970-01-01
      相关资源
      最近更新 更多