Hi. I’d like to create a view that will select a random document of a specified type. For example, let’s say I have the following documents:
{
"uid": 1,
"name": "Bill",
"company": "ABC"
}
{
“uid”: 2,
“name”:“Todd”,
“company”:“ABC”
}
{
“uid”: 14,
“name”: “Sara”,
“company”: “DEF”
}
I’d like to create a view that will get a single employee from company ABC, by random index. I’m new to Couchbase, so my logic may be way off, but I’m thinking I must first know the total number of documents with “company” equal to “ABC” (N), then generate a random number < N, and finally get the document in that index.
That seems complicated compared to how you’d get a random row, so I’m wondering if I’m missing something here. Is there a way to accomplish this in a view? If anyone could point me in the right direction, it would be greatly appreciated. Thanks!