Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | SDKs | SDKs

couchbase-python-client and _all_docs

3 replies [Last post]
  • Login or register to post comments
Sun, 02/03/2013 - 10:51
anna
Offline
Joined: 01/29/2013
Groups: None

Hi, I need to get a list of all documents stored in the database. How can I do this with couchbase-python-client?
I found the class CouchdbReader, but I think it does not work. The construction bucket.view ('_all_docs') gives an error, sо I do the following:

class Cdb(object):
    def __init__(self, *args, **kwargs):
        self.couchbase = Couchbase(':'.join([COUCHBASE['ip'],COUCHBASE['port']]), COUCHBASE["username"],COUCHBASE['password'])
        self.bucket = self.couchbase[COUCHBASE["bucket"]]
        self.limit=10
        self.rest = RestConnection(COUCHBASE)
        self.base_url = "http://{0}:{1}".format(COUCHBASE['ip'], 8092)
        self.items = self.get_data()
 
    def get_data(self, startkey=None):
        api = '/{0}/{1}?'.format(COUCHBASE["bucket"], '_all_docs')
        if self.limit:
            api+='limit=%s'%str(self.limit+1)
        if startkey:
            api+='&startkey="%s"'%startkey
        headers = self.rest._create_capi_headers()
        status, content = self.rest._http_request(api, headers=headers,base=self.base_url)
        items = json.loads(content)
        return items.get('rows',[])
 
    def __iter__(self):
        return self
 
    def next(self):
        if len(self.items) < 1:
            raise StopIteration()
        elif len(self.items) == 1:
            self.items = self.get_data(startkey=self.items[0]['key'])
            data = self.items.pop(0)
        else:
            data = self.items.pop(0)
        return data

Tell me, please, what are other ways to solve this problem?

Top
  • Login or register to post comments
Mon, 02/04/2013 - 02:22
tgrall
Offline
Joined: 09/05/2012
Groups: None

Hello,

The all_docs view is an internal view that is not documented nor supported.

So if you want to do this you will need to create your own view and emit the field you want.

This is probably the only use case where emitting the doc ID is interesting:

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

For which type of use case do you need this?

Regards

__________________

Tug
@tgrall

Top
  • Login or register to post comments
Fri, 04/19/2013 - 04:52
ville
Offline
Joined: 04/19/2013
Groups: None

The the migration/dump script (couchbase-migrator.py) shipped with couchbase-python-client also fails because of this:

couchbase-migrator.py --source=couchbase://user:pw@localhost:8091/mybucket --destination=dir://dump

[2013-04-19 14:36:08,470] - [rest_client] [140735186164064] - ERROR - http://127.0.0.1:8092/mybucket/_design/_all_docs/_view/None?limit=101&st... error 404 reason: not_found {"error":"not_found","reason":"Design document _design/_all_docs not found"}

Traceback (most recent call last):
File "/Users/ville/.virtualenvs/couchbase/lib/python2.7/site-packages/couchbase/utils/couchbase-migrator.py", line 132, in
reader = couchbase.migrator.reader(config.source)
File "/Users/ville/.virtualenvs/couchbase/lib/python2.7/site-packages/couchbase/migrator/__init__.py", line 40, in reader
return CouchbaseReader(fp)
File "/Users/ville/.virtualenvs/couchbase/lib/python2.7/site-packages/couchbase/migrator/migrator_couchbase.py", line 50, in __init__
include_docs=True)
File "/Users/ville/.virtualenvs/couchbase/lib/python2.7/site-packages/couchbase/client.py", line 332, in view
params, limit)
File "/Users/ville/.virtualenvs/couchbase/lib/python2.7/site-packages/couchbase/rest_client.py", line 266, in view_results
+ repr(status) + "\n" + content)
Exception: unable to obtain view results for mybucket/_design/_all_docs/_view/None?limit=101&stale=false&reduce=false&include_docs=true
False
{"error":"not_found","reason":"Design document _design/_all_docs not found"}

Isn't this a bug in the tools supplied with couchbase-python-client that it relies on this unsupported API?

Top
  • Login or register to post comments
Thu, 04/25/2013 - 12:08
vmx
Offline
Joined: 02/14/2011
Groups: None

As Tug says, the recommend way it to use a View.

The current SDK has plenty of problems. All energy is currently spent on a new SDK which is a complete rewrite. Best for now is to wait for the new SDK to arrive.

If you've any specific problems, please post them, so we can make sure to get those features work in the new SDK as soon as possible.

Cheers,
Volker

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker