| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 | package svcimport (	"golib/features/mo")type Operator interface {	Build() mo.D}// OptionUpdate 更新文档选项, 通常情况下// https://www.mongodb.com/docs/manual/reference/operator/update-field/type OptionUpdate struct {	CurrentDate mo.D	Set         mo.D}// SetCurrentDate 设置更新时间// TODO 也可以设置子 map key 的时间, 详情参见 example: https://www.mongodb.com/docs/manual/reference/operator/update/currentDate/#examplefunc (o *OptionUpdate) SetCurrentDate() {	o.CurrentDate = mo.D{		{Key: "$currentDate", Value: mo.D{			{Key: "lastModified", Value: true},		}},	}}// SetSet 设置需要更新的字段////	$set: {//	       "cancellation.reason": "user request",//	       status: "D"//	    }func (o *OptionUpdate) SetSet(d any) {	o.Set = mo.D{{Key: "$set", Value: d}}}func (o *OptionUpdate) Build() mo.D {	op := mo.D{}	if o.CurrentDate != nil {		op = append(op, o.CurrentDate...)	}	if o.Set != nil {		op = append(op, o.Set...)	}	return op}
 |