0

How would I do a "where or" query in couchDB? I am used to SQL and would normally do something like:

SELECT * FROM Customers
WHERE City='Berlin'
OR City='München';

I have a basic view in futon that looks like:

function(doc) {
  if(doc.city) {
    emit(doc.city, doc);
  }
}
Community
  • 1
  • 1
Rob H
  • 36
  • 3
  • Does it have an `IN` operator, like `WHERE City IN ('Berlin', 'Munchen')`? – Barmar May 07 '14 at 18:00
  • The above SQL was just an example! But yes the IN operator is another good example. If I can do this in CouchDB or the jQuery couch library that be great! – Rob H May 07 '14 at 18:04

1 Answers1

2

With a simple view index like this (ie: does not emit an array as it's key) you can query a view for multiple keys very easily. Instead of using a GET request, use a POST and send a body like:

{
  "keys": [
    "Berlin",
    "München"
  ]
}

Refer to the documentation for more details.

Dominic Barnes
  • 28,083
  • 8
  • 65
  • 90