Writing a View - like "IN" in SQL


#1

Can you please help me to create a View which is equivalent of below select or solution on below as I have multiple fields where I need to use IN

SELECT * FROM Bucket WHERE CustomerId IN (10, 20, 30) AND DepartmentId IN (4, 5, 6)

Json data example

{
“FirstName”: “Nick”,
“CustomerId”:10,
“DepartmentId” : 4
},
{
“FirstName”: “Mathew”,
“CustomerId”:20
"DepartmentId" : 6
},
{
“FirstName”: “Abhiijt”,
“CustomerId”:15,
“DepartmentId” : 2
}

Thanks for your help in advance

Rgds,

Abhi


#2

This isn’t really NoSQL way of thinking.
You’re trying to match multiple fields with multiple inputs.

You’ll need to rethink it and build views that query one thing at a time.

For example if your key was:
[department_id, customer_id, name]

Then you can view all customers for a speific (or range) of department_ids, or all names from a range of customer_ids with the department_id specified. However you can’t view a range of department_ids, combined with a range of customer_ids. You have to fill the keys from left to right, including one to query the next.

Example “query”:
startkey = [“department1”, “customer1”]
endkey = [“department1”, “customer9”]

Example “like ‘customer%’ “query”:
startkey = [“department1”, “customer”]
endkey = [“department1”, “customer”.json_decode(’”\u0fff"’)]

Odd character set in these comments, that Yen symbol or whatever should be a slash. 0fff, a high numbered character, resulting in matching anything customer*.

[department_id, customer_id]
With this you can view all customer_ids for a department_id.

[customer_id, department_id]
Or all departments for a customer_id.