【问题标题】:How to set group = true in couchdb如何在 couchdb 中设置 group = true
【发布时间】:2017-05-01 21:18:13
【问题描述】:

我正在尝试使用 map/reduce 来查找 couchDB 中的重复数据 地图功能是这样的:

function(doc) {
   if(doc.coordinates) { 
       emit({
           twitter_id: doc.id_str, 
           text: doc.text,
           coordinates: doc.coordinates
       },1)};
   }
}

reduce 函数是:

function(keys,values,rereduce){return sum(values)}

我想在同一个键中找到数据的总和,但它只是将所有内容加在一起,我得到了结果:

<Row key=None, value=1035>

这是组的问题吗?如何将其设置为 true?

【问题讨论】:

    标签: python couchdb


    【解决方案1】:

    假设您使用的是 pypi 中的 couchdb 包,您需要将包含所需所有选项的字典传递给视图。

    例如:

    import couchdb
    
    # the design doc and view name of the view you want to use
    ddoc = "my_design_document"
    view_name = "my_view"
    
    #your server
    server = couchdb.server("http://localhost:5984")
    db = server["aCouchDatabase"]
    #naming convention when passing a ddoc and view to the view method
    view_string = ddoc +"/" + view_name
    #query options
    view_options = {"reduce": True,
                    "group" : True,
                    "group_level" : 2}
    #call the view
    results = db.view(view_string, view_options)
    
    for row in results:
        #do something
        pass
    

    【讨论】:

      猜你喜欢
      • 2015-01-16
      • 1970-01-01
      • 2013-05-03
      • 2017-08-28
      • 2021-12-17
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2018-09-14
      相关资源
      最近更新 更多