cloudant:更新文档以替换现有数据
cloudant: update document which replace existing data
我有以下文件
{
"_id": "9036472948305957379",
"_rev":"162de87a696361533791aa7",
"firstname":"xyz",
"lastname": "abc"
}
现在我想更新上面的文档如下
{
"_id": "9036472948305957379",
"_rev":"162de87a696361533791aa7",
"name":"xyz abc"
}
如果我执行 doc['name'] = "xyz abc" 它不会删除名字和姓氏属性。我该如何实现?
您需要从文档的本地副本中明确删除 firstname
和 lastname
属性,然后再将其保存回数据库。
如果我对你的问题的理解是正确的,那么当你启动更新操作时,你当前正在向数据库发送以下文档正文(隐式或显式):
{
"_id": "9036472948305957379",
"_rev":"162de87a696361533791aa7",
"firstname":"xyz",
"lastname": "abc",
"name":"xyz abc"
}
但是,您的负载需要如下所示:
{
"_id": "9036472948305957379",
"_rev":"162de87a696361533791aa7",
"name":"xyz abc"
}
如果您使用的是 python-cloudant
库,请查看 http://python-cloudant.readthedocs.io/en/latest/document.html 中的 field_set
方法:
static field_set(doc, field, value)
Sets or replaces a value for a field in a locally cached Document object. To remove the field set the value to None.
我有以下文件
{
"_id": "9036472948305957379",
"_rev":"162de87a696361533791aa7",
"firstname":"xyz",
"lastname": "abc"
}
现在我想更新上面的文档如下
{
"_id": "9036472948305957379",
"_rev":"162de87a696361533791aa7",
"name":"xyz abc"
}
如果我执行 doc['name'] = "xyz abc" 它不会删除名字和姓氏属性。我该如何实现?
您需要从文档的本地副本中明确删除 firstname
和 lastname
属性,然后再将其保存回数据库。
如果我对你的问题的理解是正确的,那么当你启动更新操作时,你当前正在向数据库发送以下文档正文(隐式或显式):
{
"_id": "9036472948305957379",
"_rev":"162de87a696361533791aa7",
"firstname":"xyz",
"lastname": "abc",
"name":"xyz abc"
}
但是,您的负载需要如下所示:
{
"_id": "9036472948305957379",
"_rev":"162de87a696361533791aa7",
"name":"xyz abc"
}
如果您使用的是 python-cloudant
库,请查看 http://python-cloudant.readthedocs.io/en/latest/document.html 中的 field_set
方法:
static field_set(doc, field, value)
Sets or replaces a value for a field in a locally cached Document object. To remove the field set the value to None.