Reputation: 2046
I am starting to make a couchdb database, but unfortunately I've found an error that keeps me stalled.
I have in the database some documents like this:
{
"_id": "001169c8-16a9-400b-831d-61f4134e1cd3",
"_rev": "2-c95e7385f0ad6a249906a8a2e60341de",
"type": "word",
"word": "quién",
"creation-date": "2020-12-19T19:54:06.954539",
"sentences": {
"00789ff2-e38e-414b-a3f5-c2282aeeb42e": {
"sentence": "No sé quién se lo ha metido por la cabeza, dice que le pongo en ridículo si no voy",
"source": "foundation",
"date": "2020-12-19T19:47:48.114888"
},
"01b40374-1103-4fd5-95dd-fd5d8eddbd21": {
"sentence": "— Y a vuestra merced, ¿quién le fía, señor cura",
"source": "foundation",
"date": "2020-12-19T19:43:10.510990"
}
}
}
And I've designed a view to recover only the "word" part of these documents:
function (doc) {
if( doc.type == 'word')
emit(doc.word, 1);
}
Finnally, in python, I've created a simple script to recover the docs in that view:
def processEntries( db : couchdb.Database ):
for row in db.iterview( '_design/all_words', 100, group=True ) :
print( f"{row=}")
But unfortunately, I am getting this error (only last lines are shown):
File "/home/rluna/wkcpp/lib/corpus_env/lib/python3.8/site-packages/couchdb/client.py", line 1041, in iterview
rows = list(self.view(name, wrapper, **options))
File "/home/rluna/wkcpp/lib/corpus_env/lib/python3.8/site-packages/couchdb/client.py", line 1361, in __len__
return len(self.rows)
File "/home/rluna/wkcpp/lib/corpus_env/lib/python3.8/site-packages/couchdb/client.py", line 1378, in rows
self._fetch()
File "/home/rluna/wkcpp/lib/corpus_env/lib/python3.8/site-packages/couchdb/client.py", line 1366, in _fetch
self._rows = [wrapper(row) for row in data['rows']]
KeyError: 'rows'
Any ideas of what's going on?
Upvotes: 1
Views: 385
Reputation: 2046
Found the problem. First of all, the group=True
is incorrect for this context, because I don't want to group the results at all.
Secondly, the problem was in the way the view has to be called. The view is inside a design document, so to uniquely identify the view, you have to provide the name of the design document and the view document. In other words, the python code has to be changed this way:
def processEntries( db : couchdb.Database ):
for row in db.iterview( 'all_words/all_words', 100 ) :
print( f"{row=}")
Upvotes: 2