javascript - How to emit two separate documents concurrently in CouchDB? -
in couchdb concurrently emit object of type country , of type city. possible in 1 function?
via linked documents can emit object value {_id:doc.xxx} so:
function(doc) { if (doc.cities) { (var in doc.cities) { emit(doc.name, {_id: doc.cities[i]}); } } } the function down below suggestions it's not working because second if-part never reached.
function(doc) { if (doc.type == 'country') { emit(doc.name, null); } else if (doc.cities) { (var in doc.cities) { emit(doc.name, {_id: doc.cities[i]}); } } } documents:
// country { "_id": "country.123", "name": "france", "type": "country", "cities": [ "city.123" ] } // city { "_id": "city.123", "name": "paris", "type": "city", } update 1
i tried removing else if dominic suggested. nothing gets emitted unfortunately.
function(doc) { if (doc.type == 'country') { emit(doc.name, null); (var in doc.cities) { emit(doc.name, {_id: doc.cities[i]}); } } }
i assume want emit country document plus linked city document?
function(doc) { if (doc.type == 'country') { emit(doc._id, doc) if (doc.cities) { (var in doc.cities) { emit(doc.name, {_id: doc.cities[i]}); } } } }
Comments
Post a Comment