简体   繁体   English

合并-Google Cloud Datastore中的upsert / delete

[英]merge - upsert/delete in google cloud datastore

I am working on a POC (to move part of functionality from relational DB to cloud datastore). 我正在研究POC(将部分功能从关系数据库迁移到云数据存储)。 I have few questions: 我有几个问题:

  1. I would need to refresh few "kind" every night as the data comes up from a different data source (via flat files). 由于数据来自不同的数据源(通过平面文件),我每晚都需要刷新一些“种类”。 I read about it, and understood that there is not TRUNCATE kind of functionality in datastore. 我读了一下,并了解到数据存储中没有TRUNCATE类型的功能。 I believe, only option is to retrieve the keys from the "kind" in a loop and delete entity by entity. 我相信,唯一的选择是在循环中从“种类”中检索键并逐个删除实体。 And use import functionality to load the new set of data. 并使用导入功能加载新的数据集。 Is there any better option? 有没有更好的选择?
    1. Assume I have a kind called department, and a kind called store. 假设我有一个叫做部门的部门,还有一个叫做商店的部门。 Now, I need a kind called dept-store. 现在,我需要一种叫做dept-store的类型。 So for this parent nodes are department and store. 因此,对于此父节点,是部门和存储。 Is there a way to enforce this kind of relationship? 有没有办法加强这种关系? From the documentation I see that there can only be one parent. 从文档中,我看到只能有一个父母。
    2. If i have a child entity in kind1 whose parent is present in kind2, and they are linked together, is there a way to query all the properties present in kind1 and kind2 together? 如果我在kind1中有一个子实体,其父级在kind2中存在,并且它们链接在一起,是否可以同时查询在kind1和kind2中存在的所有属性? From relational DB perspective, it is like equi-join with "SELECT *". 从关系数据库的角度来看,它与“ SELECT *”等效连接。 I am looking for an equivalent functionality in datastore. 我正在寻找数据存储中的等效功能。

In order to answer your questions: 为了回答您的问题:

  1. There is two ways to delete multiple entities. 有两种删除多个实体的方法。 First, you can use Cloud Dataflow to delete entities in Bulk [ 1 ]. 首先,您可以使用Cloud Dataflow删除Bulk [ 1 ]中的实体。 Second, once keys are retrieved you can make a batch delete operation by passing the keys to Datastore delete function, you have the usage example here [ 2 ]. 其次,一旦检索到密钥,就可以通过将密钥传递给数据存储删除功能来进行批量删除操作,这里有使用示例[ 2 ]。 In order to retrieve the keys you can run keys-only query [ 3 ]. 为了检索密钥,您可以运行仅密钥查询[ 3 ]。

  2. In Datastore an entitiy can have only one parent but can have multiple children. 在数据存储区中,一个实体只能有一个父级,但可以有多个子级。 But for your use case you may try to have a third kind, dept-store, and assign its properties as the keys of the entities from the department and the store kinds. 但是对于您的用例,您可以尝试拥有第三种类型的百货商店,并将其属性分配为部门和商店类型中实体的键。 This solution might need a good understanding of your neeeds for implementation, as Datastore by nature is Non-relational database. 该解决方案可能需要对实现的需求有充分的了解,因为数据存储本质上是非关系数据库。

  3. You can lookup multiple entities providing the keys retrieved from kind1 and kind2 with batch operations [ 2 ]. 您可以查找多个实体,并通过批处理操作[ 2 ]提供从kind1和kind2检索到的密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM