package mongodbAPI import ( "bytes" "encoding/json" ) type ( // DeleteOneQuery represents the type used to remove a single element from the database // swagger:model DeleteOneQuery struct { Query interface{} `json:"query"` BsonID bool `json:"bson_id,omitempty"` } // DeleteManyQuery represents the type used to remove multiple elements from the database // swagger:model DeleteManyQuery struct { Query interface{} `json:"query"` BsonID bool `json:"bson_id,omitempty"` } // Delete type defines the response data for a Delete method when // calling the mongo API Delete struct { DeletedCount int `json:"deleted_count"` } ) // DeleteOne method takes a mongodbAPI client as a pointer receiver and // calls the mongo using the /DeleteOne URI func (d *Client) DeleteOne(q *DeleteOneQuery, table string) (Delete, error) { var resp Delete payload, err := json.Marshal(q) if err != nil { return resp, err } byt, err := d.post(payload, table+"/DeleteOne") if err != nil { return resp, err } if err := json.NewDecoder(bytes.NewReader(byt)).Decode(&resp); err != nil { return resp, err } return resp, nil } // DeleteMany method takes a mongodbAPI client as a pointer receiver and // calls the mongo using the /DeleteMany URI func (d *Client) DeleteMany(q *DeleteManyQuery, table string) (Delete, error) { var resp Delete payload, err := json.Marshal(q) if err != nil { return resp, err } byt, err := d.post(payload, table+"/DeleteMany") if err != nil { return resp, err } if err := json.NewDecoder(bytes.NewReader(byt)).Decode(&resp); err != nil { return resp, err } return resp, nil }