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

前端 未结 5 735
佛祖请我去吃肉
佛祖请我去吃肉 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:36

    I agree with @meliodas:

    Here's the distribution of option 2 (n=1000):

    { 0.2: 233,
      0.9: 767 }
    

    And with swapping startkey/endkey half the time:

    { 0.2: 572,
      0.9: 428 }
    

    Not sure what happens to the distribution when you look at more data, but it initially seems a bit more promising. This is without using option 1 at all, which I don't think is necessary.

提交回复
热议问题