1

I'm using couch db to store subscription documents. While performing queries, I want to be able to query on multiple properties and also use an "IN" clause. For example, I have a subscriptionStatus property which can have multiple values (Active, Failed, In_Progress etc.) and subscriptions also have a customerID.

How can I create a query for all subscriptions where customerID = "JD212S" AND subscriptionStatus IN ["Active", "In_Progress"]

Essentially show me active and in progress subscriptions for a particular customer. I looked at combinations of views, multiple keys etc but I was not able to do this (or I've misunderstood the docs).

I've had a look at a number of Stack Overflow Q/A and CouchDB docs for this but seem to find options only for a single property at a time.

1

1 Answer 1

5

it does look list a duplicate, but in your context you would create a view return multiple keys then when executing that view, like the link here states, pass in your multi-key options

// view foo/bar
var view = function(doc) {
   doc.emit([doc.customerId, doc.subscriptionStatus]);
}

db.view('foo/bar', { keys: [['JD212S','Active'], 
['JD212S','In_Progress']], include_docs: true });
Sign up to request clarification or add additional context in comments.

1 Comment

Ah thanks! I will try this. My confusion was I didn't realize I could specify the keys like so and was working out how to put them all in a single array. So essentially, each entry in the keys array is a complex key (JSON Array) in itself. Got it! It does mean though, for e.g. if I had many with many values, I'd be creating all combinations of complex key :) Anyways, thanks a lot for the answer, this is what I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.