Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更新从MyTouch扩展调用的函数_C#_Couchdb_Mycouch - Fatal编程技术网

C# 更新从MyTouch扩展调用的函数

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

我正在尝试从MyTouch调用更新函数。MyCuch的文档只报告了一个过时的示例,该示例在设计文档上使用了Post方法。 但是如何使用更新函数呢

{
  "_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
  ]
}