I've got race participant data in some documents, organized by race stage, runner position, and the time the runner passed through the stage.
I need to find a particular bib (?key=357) and grab the last time it went through a stage (doc.bib_data[i].time), which stage it was (id) and the position (i).
If I specify a particular bib_data array index, I get results, but if I loop through the bib_data, I don't get any results, even if I don't filter for anything.
VIEW with a specific index, to show what the document data looks like:
function (doc, meta) {
emit(doc.bib_data[2].bib,doc.bib_data[2].time);
}
RESULT:
{
"id": "007",
"key": "357",
"value": "1910:38",
"doc": {
"_id": "007",
"_rev": "4-bdce057c8ad2ce975b9ffca9eb9dfd82",
"ew_ham": "KM6WKA",
"stage_ew_ham": "KK6DA",
"bib_data": {
"1": {
"bib": "45",
"time": "1910:35"
},
"2": {
"bib": "357",
"time": "1910:38"
},
"3": {
"bib": "22",
"time": "1910:40"
}
}
}
}
How do I get results ONLY for "bib:357"?
I need to collect the stage, the position and the time, i.e. ["007","2","1910:38"]
"2": {
"bib": "357",
"time": "1910:38"
},
Here's my current QUERY:
http://[IP_ADDR]:5984/[DB_NAME]/_design/[DESIGN_DOC]/_view/[VIEW_NAME]?key=123
And my VIEW that attempts to loop through bib_data:
function (doc, meta) {
for(i=0;i<doc.bib_data.length;i++) {
if(doc.bib_data[i].bib) {
emit( i, doc.bib_data[i].bib, doc.bib_data[i].time );
}
}
}
Which returns no results.