计数表中的记录

时间:2019-01-30 11:04:25

标签: go rethinkdb rethinkdb-go

我正在尝试获取一张表的记录数,但是它不返回任何值。我在Rethinkdb Console中尝试过,查询返回了我想要的结果。 代码是:

    type OcorrenciasContagem struct {
        TipoOcorrencia string
        Contagem       int
    }

    ocorrenciasContagem := []OcorrenciasContagem{}

    res, err := r.Table("smpcRegistoOcorrencias").Group("tipoOcorrencia").Filter(func(row r.Term) r.Term {

        return row.Field("dataOcorrencia").Match("^2018")

    }).Count().Run(session.Sessions)

    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
    }

    err = res.All(&ocorrenciasContagem)
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }

    fmt.Printf("%+v",ocorrenciasContagem)

我得到的结果是{TipoOcorrencia:Contagem:0} {TipoOcorrencia:Contagem:0}

我希望,例如: { “ group”:“ ApoioàsForçasdeSegurança”, “减少”:1 }, { “ group”:“ Busca e Resgate Terrestre de Animais”, “减少”:1 }

0 个答案:

没有答案
相关问题