How do I get all keys from couchbase?

I am using python language to get all keys from couchbase, following code:

function(doc, meta){
    emit(null, meta.id);
}

      

this is the view in the "namedb" bucket;

from couchbase import Couchbase
db = Couchbase.connect(bucket="namedb", host="192.168.1.170", port=8091)
name = 'key'
view = 'all'
skip=0
limit = 10000
fd = open("name.txt", "a", 0)
num = 1000000
while skip < num:
    result = db.query(name, view, use_devmode = False, limit = limit, skip = skip)
    for row in result:
        fd.write(row.value + '\n')
    skip += limit
fd.close()

      

there are 1,000,000 documents in this bucket, and with skip = 210,000, the result variable will receive an empty result;

I ask for this program many times; when skip = 210000, the db.query () function always returns an empty result; how can i solve it? how can i get all the keys in this bucket? thank

+3


source to share





All Articles