我正在使用 go 和 echo 制作 rest API,并且正在更新数据。起初我使用 struct 来存储有效负载,然后对 mongodb 进行更新
type updatePayload struct {
FullName string `json:"fullName" bson:"fullName"`
FirstName string `json:"firstName" bson:"firstName"`
LastName string `json:"lastName" bson:"lastName"`
Location string `json:"location" bson:"location"`
Gender string `json:"gender" bson:"gender"`
State string `json:"state" bson:"state"`
Subdistrict string `json:"subdistrict" bson:"subdistrict"`
Address string `json:"homeAddress" bson:"homeAddress"`
Profession string `json:"provession" bson:"provession"`
Settings struct {
Email bool `json:"email" bson:"email"`
SMS bool `json:"sms" bson:"sms"`
GCM bool `json:"gcm" bson:"gcm"`
} `json:"settings" bson:"settings"`
Coordinates struct {
Type string `json:"type" bson:"type"`
Coordinates []float64 `json:"coordinates" bson:"coordinates"`
} `json:"coordinates" bson:"coordinates"`
}
更新正在工作,但如果我没有发送所有参数,例如只发送一个字段,其余字段将更新为,只是它是一个空字符串“”
有什么办法我只能更新请求有效负载上指定的字段。
呼如林
蝴蝶不菲
呼唤远方
随时随地看视频慕课网APP
相关分类