C# 更新从MyTouch扩展调用的函数
我正在尝试从MyTouch调用更新函数。MyCuch的文档只报告了一个过时的示例,该示例在设计文档上使用了Post方法。 但是如何使用更新函数呢C# 更新从MyTouch扩展调用的函数,c#,couchdb,mycouch,C#,Couchdb,Mycouch,我正在尝试从MyTouch调用更新函数。MyCuch的文档只报告了一个过时的示例,该示例在设计文档上使用了Post方法。 但是如何使用更新函数呢 { "_id": "_design/artists", "language": "javascript", "views": { "albums": { "map": "function(doc) { if(doc.$doctype !== 'artist') return; emit(doc.name, doc
{
"_id": "_design/artists",
"language": "javascript",
"views": {
"albums": {
"map": "function(doc) { if(doc.$doctype !== 'artist') return; emit(doc.name, doc.albums);}"
}
}
};
client.Documents.Post(designDocumentAsJson);
如何在推送新文档的_designcouchdb上执行更新功能
couchDB文档说明了这个调用
PUT /{db}/_design/{ddoc}/_update/{func}/{docid}
PUT/{db}/{ddoc}/{U update/{func}/{docid}
Executes update function on server side for the specified document.
Parameters:
db – Database name
ddoc – Design document name
func – Update function name
docid – Document ID
您可以将如下设计文档插入数据库:
无串接功能:
function(doc, req) {
if (!doc){
return [null, {'code': 400,
'json': {'error': 'missed',
'reason': 'no document to update'}}]
} else {
var body = JSON.parse(req.body);
doc.albums.push(body.album);
return [doc, {'json': {'status': 'ok'}}];
}
}
示例文档:
Api之后
请求:
答复:
更新后的文档
{
"_id": "albumsId1",
"_rev": "19-7edb16db3bae388685f554138d562bd0",
"albums": [
1,
2
]
}
{
"_id": "albumsId1",
"albums": [
1
]
}
POST http://localhost:5984/test/_design/albums/_update/addAlbum/albumsId1
Content-Type:application/json
Accept:application/json
{"album":2}
{
"status": "ok"
}
{
"_id": "albumsId1",
"_rev": "19-7edb16db3bae388685f554138d562bd0",
"albums": [
1,
2
]
}