I want to be able to query all users with a certain role or channel. Is it possible to index users in a view like this?
Are you talking about user documents that have been inserted into a Couchbase Lite database?
No, I mean users in the sync gateway. I have a number of CBL users, and I want to index there roles and channel access.
The way that views work is that they index documents based on the fields in the document and the map/reduce functions that are provided to build the views (see sync gateway views docs
So you should make sure your document fields have enough information to construct the views. For example, you may need to enhance your document to (redundantly) specify the their roles and channels, even if that information is stored elsewhere in sync gateway.
Oh wait, I misunderstood your question. Will look into this and get back to you.
Because the Sync Gateway user docs are private to Sync Gateway, and may change at any time, it’s not recommended to write views against them.
Currently the only thing provided are Sync Gateway Admin REST APIs for querying users and roles, but they don’t have much in the way in terms of filtering.
Can you give more details about your use case? This might serve as guidance for future API enhancements.
The use case at the moment it just that I was wanting to know which users had access to a channel. I can see which channels a user has access to, but not the other way around. Same goes for roles.
As you’ve seen, Sync Gateway is currently optimized for channel and role retrieval in the other direction (user -> channels and roles).
We’ve been considering an enhancement (as part of Admin UI enhancements) to support a lookup in the other direction. This would be a relatively expensive view query, since the user docs don’t calculate and store the channels/roles granted by the sync function until that user logs in.
If you can share any additional specifics of your use case (i.e. why it’s useful to know the set of users for a role or channel), that might help getting this enhancement prioritized.
Thanks for the reply. I’ll give it some thought