不断获取reduce函数的null值

时间:2015-06-15 15:33:49

标签: curl couchdb

我的数据如下:

{

   "_id": "33d4d945613344f13a3ee929337b1ca8",
   "_rev": "1-427c691a5c5f504c6b1d885b6b9ff4bc",
   "release": {
       "genres": {
           "genre": "Electronic"
       },
       "identifiers": {
           "identifier": [
               {
                   "description": "Text",
                   "value": "5 021603 054028",
                   "type": "Barcode"
               },
               {
                   "description": "String",
                   "value": 5021603054028,
                   "type": "Barcode"
               },
               {
                   "value": "MAYKING WAP54CD",
                   "type": "Matrix / Runout"
               }
           ]
       },
       "status": "Accepted",
       "videos": {
           "video": [
               {
                   "title": "Autechre - Lost",
                   "duration": 471,
                   "description": "Autechre - Lost",
                   "src": "http://www.youtube.com/watch?v=R7EoDcb9738",
                   "embed": true
               },
               {
                   "title": "djarum - autechre.flv",
                   "duration": 434,
                   "description": "djarum - autechre.flv",
                   "src": "http://www.youtube.com/watch?v=gaRTvCUcBJo",
                   "embed": true
               },
               {
                   "title": "Flutter [33 ⅓ Speed]",
                   "duration": 807,
                   "description": "Flutter [33 ⅓ Speed]",
                   "src": "http://www.youtube.com/watch?v=JX3sLwcEWmM",
                   "embed": true
               },
               {
                   "title": "Autechre - Flutter",
                   "duration": 598,
                   "description": "Autechre - Flutter",
                   "src": "http://www.youtube.com/watch?v=EZFmZ0gZNZI",
                   "embed": true
               }
           ]
       },
       "labels": {
           "label": {
               "catno": "WAP54CD",
               "name": "Warp Records"
           }
       },
       "companies": {
           "company": [
               {
                   "id": 264514,
                   "catno": "",
                   "name": "Warp Records Limited",
                   "entity_type_name": "Phonographic Copyright (p)",
                   "resource_url": "http://api.discogs.com/labels/264514",
                   "entity_type": 13
               },
               {
                   "id": 264514,
                   "catno": "",
                   "name": "Warp Records Limited",
                   "entity_type_name": "Copyright (c)",
                   "resource_url": "http://api.discogs.com/labels/264514",
                   "entity_type": 14
               },
               {
                   "id": 265170,
                   "catno": "",
                   "name": "Warp Music",
                   "entity_type_name": "Published By",
                   "resource_url": "http://api.discogs.com/labels/265170",
                   "entity_type": 21
               },
               {
                   "id": 45746,
                   "catno": "",
                   "name": "EMI Music",
                   "entity_type_name": "Published By",
                   "resource_url": "http://api.discogs.com/labels/45746",
                   "entity_type": 21
               },
               {
                   "id": 147881,
                   "catno": "",
                   "name": "Mayking",
                   "entity_type_name": "Pressed By",
                   "resource_url": "http://api.discogs.com/labels/147881",
                   "entity_type": 17
               }
           ]
       },
       "styles": {
           "style": "IDM"
       },
       "formats": {
           "format": {
               "text": "",
               "name": "CD",
               "qty": 1,
               "descriptions": {
                   "description": "EP"
               }
           }
       },
       "country": "UK",
       "id": 158,
       "released": "1994-09-03",
       "artists": {
           "artist": {
               "id": 41,
               "anv": "",
               "name": "Aphex Twin",
               "role": "",
               "tracks": "",
               "join": ""
           }
       },
       "title": "Anti EP",
       "master_id": 1315,
       "tracklist": {
           "track": [
               {
                   "position": 1,
                   "duration": "7:24",
                   "title": "Lost"
               },
               {
                   "position": 2,
                   "duration": "7:19",
                   "title": "Djarum"
               },
               {
                   "position": 3,
                   "duration": "9:57",
                   "title": "Flutter"
               }
           ]
       },
       "data_quality": "Correct",
       "extraartists": {
           "artist": [
               {
                   "id": 445854,
                   "anv": "",
                   "name": "Designers Republic, The",
                   "role": "Design",
                   "tracks": "",
                   "join": ""
               },
               {
                   "id": 41,
                   "anv": "",
                   "name": "Aphex Twin",
                   "role": "Producer",
                   "tracks": "",
                   "join": ""
               },
               {
                   "id": 300407,
                   "anv": "Brown",
                   "name": "Rob Brown (3)",
                   "role": "Written-By",
                   "tracks": "",
                   "join": ""
               },
               {
                   "id": 42,
                   "anv": "Booth",
                   "name": "Sean Booth",
                   "role": "Written-By",
                   "tracks": "",
                   "join": ""
               }
           ]
              }
}

我试图为艺术家Aphex Twin获取价值

我使用以下代码进行映射:

function(doc){ 
if(doc.release)
emit(doc.release.artists.artist.name,doc.release.title)
}

映射已成功完成,然后我尝试过滤所有包含艺术家名称“Aphex Twin”的值。我使用了以下命令:

    function(keys, vals, rereduce) {

 for(var i = 0; i < keys.length; i++)
{if(keys[i][0]=="Aphex Twin")
return values[i]
}
}

我得到了回复

response

P.S。如果我使用键curl然后我得到错误

curl -X GET http://localhost:5984/smalldiscogs/_design/myvie
ws/_view/Aphextwin?group=false&keys="Aphex Twin"

获取所有映射结果后,我收到错误

An incorrect parameter was
    entered for the command.

1 个答案:

答案 0 :(得分:0)

地图功能:

function(doc){ 
if(doc.release)
emit([doc.release.artists.artist.name,doc.release.title],1)
}

保存后,使用网址

获取信息

Result