我是couchDB新手。我从简单的map / reduce开始。我不知道为什么我无法收到我所附的代码的正确值。提前谢谢!!!
我的映射代码如下:
function(doc){
if(doc.release.formats.format.descriptions.description == 'Album'){
doc.release.artists.artist.forEach(function(i){emit(i.name,doc.release.title)})
}
}
我的结果地图值 关键:“Trevor loveys”的价值:“时代”
我的减少代码
function(keys,values,rereduce)
{
for(var i=0; i<keys.length();i++)
{
if(keys[i] == "Trevor Loveys")
{
return values;
}
}
一旦我减少了,我就会得到答案
Key:“Trevor loveys”的价值:null
更新即可。我的json数据样本如下:
{
"release": {
"genres": {
"genre": "Electronic"
},
"status": "Accepted",
"videos": {
"video": [
{
"title": "Reflections- 2nd Nature",
"duration": 436,
"description": "Reflections- 2nd Nature",
"src": "http://www.youtube.com/watch?v=w4c8Xi56YZ8",
"embed": true
},
{
"title": "Trevor Loveys - Bra",
"duration": 414,
"description": "Trevor Loveys - Bra",
"src": "http://www.youtube.com/watch?v=DcakkW0uZcs",
"embed": true
},
{
"title": "Trevor Loveys - We can make it",
"duration": 463,
"description": "Trevor Loveys - We can make it",
"src": "http://www.youtube.com/watch?v=lJN7Wpl6HrE",
"embed": true
},
{
"title": "Trevor Loveys Forever After (ERA).mp4",
"duration": 311,
"description": "Trevor Loveys Forever After (ERA).mp4",
"src": "http://www.youtube.com/watch?v=00qmrYHgm54",
"embed": true
}
]
},
"labels": {
"label": {
"catno": "ALO CD003",
"name": "Alola"
}
},
"companies": "",
"styles": {
"style": [
"Deep House",
"Downtempo"
]
},
"formats": {
"format": {
"text": "",
"name": "CD",
"qty": 1,
"descriptions": {
"description": "Album"
}
}
},
"country": "UK",
"id": 1504,
"released": "1999-00-00",
"artists": {
"artist": [
{
"id": 2049,
"anv": "",
"name": "Trevor Loveys",
"role": "",
"tracks": "",
"join": "Presents"
},
{
"id": 8637,
"anv": "2nd Nature",
"name": "Second Nature",
"role": "",
"tracks": "",
"join": ""
}
]
},
"title": "Era",
"master_id": 11157,
"tracklist": {
"track": [
{
"position": 1,
"duration": "",
"title": "Forever After"
},
{
"position": 2,
"duration": "",
"title": "Wisdom"
},
{
"position": 3,
"duration": "",
"title": "Look To The Sky"
},
{
"position": 4,
"duration": "",
"title": "Falling Down"
},
{
"position": 5,
"duration": "",
"title": "Life Stories"
},
{
"position": 6,
"duration": "",
"title": "Rainy Afternoon"
},
{
"position": 7,
"duration": "",
"title": "Reflections"
},
{
"position": 8,
"duration": "",
"title": "Got To Go There"
},
{
"position": 9,
"duration": "",
"title": "We Can Make It"
},
{
"position": 10,
"duration": "",
"title": "No Compromise"
},
{
"position": 11,
"duration": "",
"title": "Era"
},
{
"position": 12,
"duration": "",
"title": "City 2 City"
},
{
"position": 13,
"duration": "",
"title": "Depth Charge"
}
]
},
"data_quality": "Correct",
"extraartists": {
"artist": [
{
"id": 49433,
"anv": "",
"name": "Chris Pedley",
"role": "Written-By, Producer",
"tracks": "",
"join": ""
},
{
"id": 2049,
"anv": "",
"name": "Trevor Loveys",
"role": "Written-By, Producer",
"tracks": "",
"join": ""
}
]
}
}
}
我的目的是获得艺术家“Trevor Loveys”的专辑名称
我用上面的方法来实现我的目标。但是,我无法理解它失败的原因。
答案 0 :(得分:0)
键是一个数组:
[["some_key","89a85cad58c426cd85a55bac8e0350f8"]]
您可以在reduce函数中使用log(key)
进行测试。
因此,您的if
阻止失败,并且未返回任何减少。