golang mongo-driver 如何更新某个字段
資深大佬 : aoscici 3
type Comment struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` Title string `bson:"title" json:"title" binding:"required"` Author string `bson:"author" json:"author" binding:"required"` Content string `bson:"content" json:"content" binding:"required"` Like int64 `bson:"like" json:"like"` Updated time.Time `bson:"updated" json:"updated"` } Collection.FindOneAndUpdate(ctx, filter, update, &opt).Decode(&comment)
比如这里我只传来 {“content”: “。。。”} 或者 {“author”: “11”} 这一个数据,怎么灵活得接收这个数据和只更新这一个字段?翻了很多文章貌似都是把更新项写死的。
大佬有話說 (9)