diff --git a/tools/goctl/model/mongo/readme.md b/tools/goctl/model/mongo/readme.md index e8ed8be8..1c19cc93 100644 --- a/tools/goctl/model/mongo/readme.md +++ b/tools/goctl/model/mongo/readme.md @@ -105,7 +105,7 @@ func (m *defaultUserModel) FindOne(ctx context.Context, id string) (*User, error } var data User - key := prefixUserCacheKey + data.ID.Hex() + key := prefixUserCacheKey + id err = m.conn.FindOne(ctx, key, &data, bson.M{"_id": oid}) switch err { case nil: diff --git a/tools/goctl/model/mongo/template/model.tpl b/tools/goctl/model/mongo/template/model.tpl index c07d7896..9265d13f 100644 --- a/tools/goctl/model/mongo/template/model.tpl +++ b/tools/goctl/model/mongo/template/model.tpl @@ -47,7 +47,7 @@ func (m *default{{.Type}}Model) FindOne(ctx context.Context, id string) (*{{.Typ } var data {{.Type}} - {{if .Cache}}key := prefix{{.Type}}CacheKey + data.ID.Hex(){{end}} + {{if .Cache}}key := prefix{{.Type}}CacheKey + id{{end}} err = m.conn.FindOne(ctx, {{if .Cache}}key, {{end}}&data, bson.M{"_id": oid}) switch err { case nil: