package mongodbAPI import ( "bytes" "encoding/json" ) type ( // CountQuery query will be the type used to pass into the count method CountQuery struct { Query interface{} `json:"query"` } // count type will marshal the result from the Mongo Count API call count struct { Count int `json:"count"` } ) // Count method will call out to Mongo using the count method, return value will be an int with a count // of the queried value. // { // "count": 43619 // } func (d *Client) Count(f *CountQuery, table string) (int, error) { payload, err := json.Marshal(f) if err != nil { return 0, err } byt, err := d.post(payload, table+"/Count") if err != nil { return 0, err } resp := new(count) if err := json.NewDecoder(bytes.NewReader(byt)).Decode(resp); err != nil { return 0, err } return resp.Count, nil }