mapreduce - I think I may be trying something impossible - complex Couchdb "JOIN" scenario -
i think trying here may impossible, worth shot.
i have 2 doc types, operator
, event
.
in example below, emitting 3 keys.
[place_id, operator_id, zone_name]
operator_id
, zone_name
common fields in both documents. how want join between 2 document types.
what want place_id
first key first emit(), , event
doc._id
second emit().
that way, can specific startkey place_id
want list of event._id
s for.
function(doc) { if(doc.doc_type == 'operator') { for(var in doc.zones) { for(var ii in doc.zones[i].origs) { if(doc.zones[i].origs[i]) emit([doc.zones[i].origs[i], doc._id, doc.zones[i].name], null); } } } else if (doc.doc_type == 'event') { for(var in doc.rates) { if(doc.rates[i].zone) { emit([0, doc.operator_id, doc.rates[i].zone], doc._id); } } } }
the problem join wont work first value of 0 in second emit();
i have tried emiting keys [operator_id, zone_name]
allows join work, reduce() function takes long , throws error since list of event._id
s grows long.
i have break 2 separate queries hope learn different approach missing.
everything emit()
sorted the key. often, keys arrays nice sort order: first element has highest priority, followed second element, etc. if key array, still 1 thing , whole view sorted key.
therefore, join between different documents, have sort adjacent each other in view. means should share leftmost elements of emit()
key.
p.s. not helpful talk "join"s couchdb, although people use word.
Comments
Post a Comment