迁移cloudant中的现有数据

时间:2017-01-12 22:42:29

标签: cloudant

假设我在cloudant中有这样的数据结构,这是一条记录:

{
    "UserId": "0014807347",
    "Conq": {
      "reqs": "Testing",
      "tag": "ARRANGEMENT"
    },
    "Outcome": {
      "tag": "ARRANGEMENT",
      "rating": 0
    },
    "id": "cdc11dc55a0006bb544d235e7dc1540a"
  }

如何转换特定表的每条记录以添加新字段?

1 个答案:

答案 0 :(得分:2)

使用更新的JSON正文执行具有id和当前版本的PUT:

curl https://$USERNAME:$PASSWORD@$USERNAME.cloudant.com/$DATABASE/cdc11dc55a0006bb544d235e7dc1540a\
 -X PUT \
 -H "Content-Type: application/json" \
 -d "$JSON"
{
    "_id": "cdc11dc55a0006bb544d235e7dc1540a",
    "_rev": "1-THE_CURRENT_REV_ID_HERE",
    "UserId": "0014807347",
    "Conq": {
        "reqs": "Testing",
        "tag": "ARRANGEMENT"
    },
    "Outcome": {
      "tag": "ARRANGEMENT",
      "rating": 0
    },
    "my_new_data_field": "My New Content Goes Here"
  }
}

您应该得到类型的回复:

{
  "ok":true,
  "id":"cdc11dc55a0006bb544d235e7dc1540a",
  "rev":"2-9176459034" 
}

当前版本(由上面1-THE_CURRENT_REV_ID_HERE表示)应该是您上次撰写文档时的修订版。