我有一個(gè)結(jié)構(gòu):type User struct { ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` Username *string `json:"username" bson:"username,omitempty"` FirstName *string `json:"firstName" bson:"first_name,omitempty"` LastName *string `json:"lastName" bson:"last_name,omitempty"` Email *string `json:"email" bson:"email,omitempty"` GoogleID *string `json:"googleID" bson:"google_id,omitempty"` PageURLs []string `json:"pageURLs" bson:"pages"` Schema int `json:"-" bson:"schema"` // omitted from graphql}我正在調(diào)用這段代碼:updateOption := options.FindOneAndUpdate().SetUpsert(true)updateData := bson.M{"$set": *user}filter := bson.M{"google_id": user.GoogleID}// updated user will have Iderr = findOneUserAndUpdate(context.TODO(), filter, updateData, updateOption).Decode(updatedUser)使用以下用戶:var testFirstname = "first"var testLastname = "last"var testEmail = "test@gmail.com"var testGoogleID = "abc123"testUser = &model.User{ FirstName: &testFirstname, LastName: &testLastname, Email: &testEmail, GoogleID: &testGoogleID, PageURLs: []string{}, Schema: 1,}但我收到此錯(cuò)誤消息:無法解碼為零值。這可能是因?yàn)橹羔槥榱?,但在這種情況下,omitempty 構(gòu)建標(biāo)記應(yīng)該只省略該字段。為什么會(huì)失敗呢?
- 2 回答
- 0 關(guān)注
- 244 瀏覽
添加回答
舉報(bào)
0/150
提交
取消
