在couchdb映射函数中更改对象字段的值

时间:2018-01-29 17:00:08

标签: javascript nosql couchdb

在我的视图的map函数中,我正在尝试更改javascript对象的字段。有趣的是,我不能改变一个字段而不是发出该对象。 如果irem对象是“test”,我希望所有的名称字段。但我无法改变它。任何帮助都会很棒.. 地图功能

function(doc) {
 doc.movieList.forEach(function(item){
      item.name = "test";
      emit([doc.companyId,item.movieID],item);
  });
}

结果

"rows": [
        {
            "key": [
                "147",
                "044a30f24e98660a8a8c12d09b1cafb3"
            ],
            "value": {
                "categoryID": 4,
                "dataModelVersion": 1,
                "forSale": false,
                "movieID": "044a30f24e98660a8a8c12d09b1cafb3",
                "name": "HULK",  //This field shoud be "test"
                "orderId": 99,
                "term": 0,
                "visible": true,
                "watchCount": 0
            }
        },
        {
            "key": [
                "147",
                "07c3c1bc4ac5d99286ccc54cde06b86a"
            ],
            "value": {
                "categoryID": 2,
                "dataModelVersion": 1,
                "forSale": false,
                "movieID": "07c3c1bc4ac5d99286ccc54cde06b86a",
                "name": "KACIS-PLANI", //This field shoud be "test"
                "orderId": 99,
                "term": 0,
                "visible": true,
                "watchCount": 0
            }
        },
        {
            "key": [
                "147",
                "0c6f28034e39bc94009be0375e2fba2a"
            ],
            "value": {
                "categoryID": 8,
                "dataModelVersion": 1,
                "forSale": false,
                "movieID": "0c6f28034e39bc94009be0375e2fba2a",
                "name": "YOLA-GELDIK", //This field shoud be "test"
                "orderId": 99,
                "term": 0,
                "visible": true,
                "watchCount": 0
            }
        },

1 个答案:

答案 0 :(得分:0)

检查CouchDB code,提供给map函数的文档是sealed,因此不允许对原始对象进行修改。

您需要将原始对象复制到新对象中以修改其属性。