2014-04-22 3 views
0

couchdb-python에서 group = True를 어떻게 설정할 수 있습니까?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

물론 이죠,하지만 당신은 또한 reduce function 정의해야

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