Q: about query array with N1QL

HI @vsr1,

I want query array with N1QL like as follow:

SELECT dish.name as dishName, dish.kindId FROM kitchen AS dish 
where dish.className = 'Dish' 
and meta(dish).id in
["Dish.ed6c94e3-1b7f-495e-b2de-c39435049eb7","Dish.46ad2bb6-78c5-43b2-95a4-5d7d364889e8","Dish.1624d766-6a0a-4370-ace9-ab6a4ecdd322","Dish.2c0b4f6f-2f55-4bc3-912a-3dae54da1a55","Dish.46ad2bb6-78c5-43b2-95a4-5d7d364889e8","Dish.4985258f-e82d-4fea-b677-3108e85dd1eb","Dish.ed6c94e3-1b7f-495e-b2de-c39435049eb7","Dish.126fea84-8e01-4faf-8295-080a3b7b440a"]

in the array have 8 strings as ID, but those ID duplicate, so I only get 6 record result. but I don’t want ignore those duplicate ID, still get 8 records. how can I do?

thanks!

anguar

Try this:

SELECT dish.name as dishName, dish.kindId
FROM kitchen AS dish USE KEYS [“Dish.ed6c94e3-1b7f-495e-b2de-c39435049eb7”,“Dish.46ad2bb6-78c5-43b2-95a4-5d7d364889e8”,“Dish.1624d766-6a0a-4370-ace9-ab6a4ecdd322”,“Dish.2c0b4f6f-2f55-4bc3-912a-3dae54da1a55”,“Dish.46ad2bb6-78c5-43b2-95a4-5d7d364889e8”,“Dish.4985258f-e82d-4fea-b677-3108e85dd1eb”,“Dish.ed6c94e3-1b7f-495e-b2de-c39435049eb7”,“Dish.126fea84-8e01-4faf-8295-080a3b7b440a”]
where dish.className = ‘Dish’

After predicate applied it can’t produce duplicates because meta(dish).id in ["X’,“x”,“x”] condition is only true once per document.
As you use full document keys to filter you can use approach suggested by @johan_larson you get duplicate documents. USE KEYS doesn’t required index and saves some time on IndexScan.

HI @johan_larson @vsr1,

thanks for your reply. the n1ql statement works perfectly!

angular