我有一個結構: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}我正在調用這段代碼: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 = "[email protected]"var testGoogleID = "abc123"testUser = &model.User{ FirstName: &testFirstname, LastName: &testLastname, Email: &testEmail, GoogleID: &testGoogleID, PageURLs: []string{}, Schema: 1,}但我收到此錯誤消息:無法解碼為零值。這可能是因為指針為零,但在這種情況下,omitempty 構建標記應該只省略該字段。為什么會失敗呢?
- 2 回答
- 0 關注
- 236 瀏覽
添加回答
舉報
0/150
提交
取消