Is it possible to query use liststreamkeyitems with an array of keys?

+1 vote
A lot of other API calls in Multichain 2.0 have been updated so one can pass an array of keys, however,  liststreamkeyitems seems to be exempt from this. How can I query a stream using multiple keys to return multiple items? Is there an alternate method?
asked Mar 9, 2018 by Tom

1 Answer

0 votes

I'm afraid it's not currently possible to query with multiple keys simultaneously for liststreamkeyitems (it is possible for liststreamkeys).

Just out of curiousity, would you be looking for items that have *all* of these keys, or items that have *any* of these keys? The problem in either case is that MultiChain's indexes can't be used efficiently if there are a large number of items, and start and count are used for paging in the results.

answered Mar 11, 2018 by MultiChain
The best way to illustrate what I want to do is with an example:

I want to store an object in the database, and I want an individual item in the stream for each attribute, ie:

KEY                      VALUE
user1923_color:    Red
user1923_age:      18
user3371_color:    Blue
user4344_color:    Brackish
user1923_height:   6' 0"
user3371_age:      34

This is how some KVP based NoSQL databases arrange their data. I want to bring back a particular user so I will pass in the keys [user1923_color, user1923_height] and use those values to populate the User object in my application. Obviously I can place the Multichain liststreamitems API call in a loop and pass in the keys, but any developer worth their salt knows this is unbelievably inefficient; reducing a database retrieval operation to linear time over the internet. Could you suggest some ways I could workaround this problem? Perhaps storing my objects and their attributes in a JSON object is a good solution?

Yes, you should definitely store all the attributes in a JSON object in a single stream item, rather than individual entries. If you're using Multichain 2.0 alpha, you can also store updates as JSON objects with just some of the fields, and then use getstreamkeysummary to "flatten" the entries into a single up-to-date object.
I would have expected to be able to filter for items that have *all* of the keys. Maybe a flag that indicates if one wants items with *all* or *any* of the keys would helpful.
OK, noted, we'll consider this kind of functionality in future.