I have 100 documents in a Cloudant DB with IDs from 1-100. I am trying to pull the first 50 documents at random using js.
For example, the query would pull document #47 then repeat and pull #21 so on and so forth.
I have 100 documents in a Cloudant DB with IDs from 1-100. I am trying to pull the first 50 documents at random using js.
For example, the query would pull document #47 then repeat and pull #21 so on and so forth.
You can't randomize the output of a Cloudant index on the server side -- documents are returned in lexicographical order on either the emitted key in the case of a secondary index, or the document id in the case of the primary index. If you know the range of your document ids, you can of course fetch them in any order you like using a POST to the _all_docs endpoint with a json body containing a "keys" array. But you'd need to generate this array client-side first. How to shuffle an array in javascript is well documented on this site and others.