You don’t want to use setKeys
here; you want a range of keys, not a specific set of keys.
Set startKey
to [penID]
and endKey
to [penID, {}]
. The empty map sorts after any other value, so this key range includes all keys that start with penID
, which is what you want.
The view and query docs online describe how to do this kind of thing.