How is it possible to set group=True in couchdb-python ?

from couchdb import Server
from couchdb.mapping import Document, TextField, IntegerField, DateTimeField, ViewField

server = Server()
db = server.create('python-tests2')


class Person(Document):
_id = TextField()
name = TextField()
age = IntegerField()
by_name = ViewField('people', '''\
    function(doc) {
        emit(doc.name, doc);
    }''')

person = Person(_id='Person1', name='John Doe', age=42)
person.store(db)


for row in db.query(Person.by_name.map_fun):
print row
有帮助吗?

解决方案

Sure, but you also need to define the reduce function:

for row in db.query(Person.by_name.map_fun, '_count', group=True):
  print row
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top