如何在couchdb-python中设置group = True

时间:2014-04-22 08:22:19

标签: python couchdb couchdb-python

如何在couchdb-python中设置group = True?

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

1 个答案:

答案 0 :(得分:1)

当然,您还需要定义reduce function

for row in db.query(Person.by_name.map_fun, '_count', group=True):
  print row