Have you tried to use limit instead of count ?
On Thu, Feb 19, 2009 at 7:49 AM, Craig McInnes <[email protected]>wrote:
> Hi,
>
> I'm having difficulty getting results from a permanent view using
> couchdb-python.
> I'm not sure this is the correct place to ask. Apologies if it is not.
>
> I've successfully called temporary views and stepped through results (just
> to verify them), but my understanding is that temporary views do not build
> a
> permanent b-tree index on the data (which is what I'd really like to be
> accessing).
>
> I created a permanent view a few different ways:
>
> - via futon:
> In Map Function I've added the barebones map fn:
> function(doc){emit(doc._id, null);}
> and hit SaveAS, named the view, the view is now accessible via the drop
> down.
>
> - via couchdb-python:
> <python snippet>
> view = ViewDefinition('mytest', 'myall', '''function(doc) {emit(doc._id,
> null);}''')
> view.get_doc(db)
> view.sync(db)
> </python snippet>
> and this also is accessible via the drop down in futon.
>
> - via couchdb-python:
> <python snippet>
> class MyDoc(Document):
> type = TextField()
> tags = ListField(IntegerField)
> added = DateTimeField(default=datetime.datetime.now())
> myDocByTag = View('mydocbytag', '''function(doc) {emit(doc._id,
> null);}''')
> </python snippet>
>
> I then create instances of this class and store them using: <class
> instance>.store(db)
> The class instances are correctly stored as documents in couchdb.
> This view is *not* stored in couchdb (i.e. I can't see it in the drop
> down in futon).
> Trying to invoke this view via:
> res = MyDoc.myDocByTag(db, count=3)
> print str(res)
> print dir(res)
> for r in res:
> print str(r)
>
> returns:
> <ViewResults <PermanentView '_view/mydocbytag/byTag'> {'count': 3}>
>
> ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__',
> '__getitem__', '__hash__', '__init__', '__iter__', '__len__',
> '__module__',
> '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
> '__str__', '__weakref__', '_fetch', '_get_offset', '_get_rows',
> '_get_total_rows', '_offset', '_rows', '_total_rows', 'offset',
> 'options',
> 'rows', 'total_rows', 'view']
>
> Traceback (most recent call last):
> File "ctest.py", line 277, in <module>
> for r in res:
> File
>
> "/usr/lib/python2.5/site-packages/CouchDB-0.5-py2.5.egg/couchdb/client.py",
> line 727, in __iter__
> File
>
> "/usr/lib/python2.5/site-packages/CouchDB-0.5-py2.5.egg/couchdb/client.py",
> line 744, in _get_rows
> File
>
> "/usr/lib/python2.5/site-packages/CouchDB-0.5-py2.5.egg/couchdb/client.py",
> line 737, in _fetch
> File
>
> "/usr/lib/python2.5/site-packages/CouchDB-0.5-py2.5.egg/couchdb/client.py",
> line 627, in _exec
> File
>
> "/usr/lib/python2.5/site-packages/CouchDB-0.5-py2.5.egg/couchdb/client.py",
> line 832, in get
> File
>
> "/usr/lib/python2.5/site-packages/CouchDB-0.5-py2.5.egg/couchdb/client.py",
> line 884, in _request
>
>
> Discounting the last view, I can't seem to access the first two via
> couchdb-python.
>
> I've tried:
> view = db.view('mytest/myall')
> print str(view)
> >>> <ViewResults <PermanentView '_view/mytest/myall'> {}>
> So it's definitely finding the view correctly
> (otherwise I'd see a:
> couchdb.client.ResourceNotFound: (u'not_found', u'missing')
> error).
>
> for r in view:
> print r.id
> # this prints nothing, there are no rows in view
>
>
> I've tried messing around with the PermanentView class, or invoking the
> permanent view via the MyDoc class, but no luck.
>
> I'm sure I'm missing something simple, but I need some help.
> Apologies for the long winded email.
>
> Cheers,
> -Craig
>