You can do this using couchdb linked documents.
If you emit an object value which has {'_id': XXX} then include_docs=true will fetch the document with id XXX rather than the document which was processed to emit the key/value pair.
This means that if one document contains the ids of other documents, it can cause those documents to be fetched in the view too, adjacent to the same key if required.
If you change the schema of your documents a bit and include the _id
field of the second document in the first document like so
{....,{"trip_id":"id of the document to fetch"}}
Then you can define a view like
function(doc){
emit(doc.key,{"_id":doc.trip_id});//doc.key is the key on which you want your view to be sorted.
}
now you can query like so
http://localhost:5984/db_name/_design/ddoc_name/_view/view_name?key="some-value"&include_docs=true
this will fetch the linked document. The important point to note here is the second parameter in the emit must point to the document that you want to fetch. In your case trip_id
must point to the _id
of the second document.