How do I load a random document from CouchDB (efficiently and fairly)?

前端 未结 5 730
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-03 10:46

I would like to load a random document out of a set of documents stored in a CouchDB database. The method for picking and loading the document should conform to the following re

5条回答
  •  温柔的废话
    2021-02-03 11:17

    If insert performance is not an issue you could try to make number non random e.g. make it doc_count + 1 at the time of creation. Then you could look it up with a random number 0 <= r < doc_count. But that would either require to synchronize the creation of documents or have sequence external to couchdb, e.g. an SQL database.

    Best regards

    Felix

提交回复
热议问题