diff --git a/api/handlers/cow.go b/api/handlers/cow.go index 7b02628..e37e49e 100644 --- a/api/handlers/cow.go +++ b/api/handlers/cow.go @@ -205,7 +205,7 @@ func (c Cow) AddDeviceHandler(w http.ResponseWriter, r *http.Request) { } update := bson.M{ - "cow.Devices": newDevice, + "Cow.Devices": newDevice, } dbResp, err := c.DB.UpdateOne(context.TODO(), bson.M{"_id": cowID}, bson.M{"$push": update}) diff --git a/api/handlers/device.go b/api/handlers/device.go index 41cbb6c..c034692 100644 --- a/api/handlers/device.go +++ b/api/handlers/device.go @@ -163,7 +163,7 @@ func (d Device) UpdateDeviceHandler(w http.ResponseWriter, r *http.Request) { varName := e.Type().Field(i).Name varValue := e.Field(i).Interface() if varValue != nil && varValue != "" { - update["Details."+varName] = varValue + update["Device."+varName] = varValue } } @@ -188,7 +188,7 @@ func (d Device) GetChildDevices(w http.ResponseWriter, r *http.Request) { cowID := mux.Vars(r)["cow_id"] defer cancel() - devices, _ := d.DB.Find(ctx, bson.M{"Detials.Parent": cowID}) + devices, _ := d.DB.Find(ctx, bson.M{"Device.Parent": cowID}) // If there is no devices from the query, return empty device array. if len(devices) == 0 { diff --git a/models/device.go b/models/device.go index 9f02c81..40b2657 100644 --- a/models/device.go +++ b/models/device.go @@ -3,7 +3,7 @@ package models // Device holds the structure for the device collection in mongo type Device struct { ID string `json:"_id" bson:"_id"` // MongoDB ID - Details DeviceDetails `json:"device" bson:"Details"` // Details + Details DeviceDetails `json:"device" bson:"Device"` // Details } // Device holds the structure for the Device collection in mongo