简体   繁体   English

如何使用谷歌云数据存储从实体中删除属性/值

[英]How to delete a property/value from an entity using google cloud datastore

I am learning google.cloud.datastore , and like to know how to delete a property along with its value from an entity . 我正在学习google.cloud.datastore ,并且想知道如何从entity删除属性及其值。 Also, is it possible to delete a specific or a list of properties from all entities of a certain kind ? 此外,是否可以从特定kind所有实体中删除特定属性或属性列表?

My understanding is datastore stores/manipulates data in a row-wise way ( entities )? 我的理解是datastore存储/以行方式( entities )操作数据?

cheers 干杯

Your understanding is correct, all datastore write operations happen, indeed, at the entity level. 您的理解是正确的,所有数据存储区写操作确实在实体级别发生。 So in order to modify one or a subset of properties you'd retrieve the entity, modify the property (or delete it, if you want to delete the property) set and save the entity. 因此,为了修改您要检索实体的一个或一部分属性,修改属性(或删除它,如果要删除属性)设置并保存实体。

The exact details depend on the language and library used. 确切的细节取决于使用的语言和库。 From Updating an entity : 更新实体

To update an existing entity, modify the properties of the entity and store it using the key: update现有实体,请修改实体的属性并使用密钥存储它:

PYTHON 蟒蛇

 with client.transaction(): key = client.key('Task', 'sample_task') task = client.get(key) task['done'] = True client.put(task) 

The object data overwrites the existing entity. 对象数据会覆盖现有实体。 The entire object is sent to Cloud Datastore. 整个对象将发送到Cloud Datastore。 If the entity does not exist, the update will fail. 如果实体不存在,则更新将失败。 If you want to update-or-create an entity, use upsert as described previously. 如果要更新或创建实体,请使用upsert ,如前所述。

Note : To delete a property, remove the property from the entity, then save the entity. 注意 :要删除属性,请从实体中删除该属性,然后保存该实体。

In the above snippet, for example, deleting the done property of the task entity, if existing, would be done like this: 例如,在上面的代码段中,删除task实体的done属性(如果存在)将如下所示:

with client.transaction():
    key = client.key('Task', 'sample_task')
    task = client.get(key)

    if 'done' in task:
        del task['done']
        client.put(task)

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

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