Couchdb _design / doc / _update / push不能作为对象使用

问题描述 投票:0回答:1

我想使用现有的Couchdb文档,以深度合并有关此请求的某些数据

请求::curl -H "Content-Type: application/json" -X POST http://localhost/couch/ddb/_design/data/_update/push2/cap1 -d '{"51" : 5, "65" : 2}'

数据库文档::{65: [[]], 51: [[]]};

更新功能::function(doc, req) { var d = req.body; for(var key in doc.x2) { doc.x2[key][0].push(d[key]); }; return [doc,'added'];}"

问题是包含数据的req.body显示为String,而不显示为JSON object,从而无法选择该值

查询结果应为::{65: [[2]], 51: [[5]]};

其他一切正常,期望req.bodyString而不是Object

javascript json couchdb couchapp
1个回答
1
投票

嗯,找到了我自己的答案。并不难:

[var d = req.body; >> var d = JSON.parse(req.body);并且d成为Object]

© www.soinside.com 2019 - 2024. All rights reserved.