I have two buckets in riak client_user and account_user, I am trying to make a mapreduce to get all users' objects

StackOverflow https://stackoverflow.com/questions/15485933

Question

I have two riak buckets , "client_user" which contains compose_key as key like clientid-userid and another bucket "account_user" which contains userid as key and users' information. I am trying to make one mapreduce query to find out all users info base on one client. I search out on internet, I can't find any answer. Anyone can help me with a javascript mapreduce query on riak? really appreciate it.

Was it helpful?

Solution

If the key is a composite such as clientId_userId, there is no way to query it individually to find the users associated with that client. You can list all keys; Write a javascript map phase to split the key based on a delimiter; Feed the results of this operation to a SetMemberFilter based on client ID; Use another map reduce operation on the account_user bucket with this SetMemberFilter.

Your data is not modelled correctly for Riak. Had the user info just contained a secondary index for the client ID, this would have been a simple call to that bucket. I'm afraid there is no easy answer. You can still retrieve the information using the series of steps I outlined in my answer, but it would be inefficient. There is no other way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top