database - CouchDB View With OR Condition -


i have 2 kinds of documents in couchdb following json type:

1.  {  "_id": "4a91f3e8-616a-431d-8199-ace00055763d",  "_rev": "2-9105188217acd506251c98cd4566e788",  "vehicle": {      "type": "string",      "name": "vehicle",      "value": "12345"         }, "start": {      "type": "date",      "name": "start",      "value": "2014-09-10t11:19:00.000z"        } }  2.  {    "_id": "4a91f3e8-616a-431d-8199-ace00055763d",    "_rev": "2-9105188217acd506251c98cd4566e788",    "equipment": {        "type": "string",        "name": "equipment",        "value": "12345"           }, "start": {    "type": "date",    "name": "start",    "value": "2014-09-10t11:19:00.000z"        } } 

i want make 1 view search these documents doc.vehicle.value=12345 or doc.equipment.value=12345. how can make view return these kind of documents. in advance.

just emit both (yes, map functions may emits multiple times different key-values same doc) values view:

function(doc){   if (doc.equipment) {     emit(doc.equipment.value, null)   }   if (doc.vehicle) {     emit(doc.vehicle.value, null)   } } 

and request them same key:

http://localhost:5984/db/_design/ddoc/_view/by_equip_value?key="12345" 

see guide views more info couchdb views.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -