Skip to content

Commit

Permalink
Add GetFields
Browse files Browse the repository at this point in the history
  • Loading branch information
minhduc140583 committed Jul 2, 2023
1 parent d8dd0c7 commit fc58ded
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,24 @@ func GetFieldByJson(modelType reflect.Type, jsonName string) (int, string, strin
}
return -1, jsonName, jsonName
}

func GetFields(fields []string, modelType reflect.Type) bson.M {
if len(fields) <= 0 {
return nil
}
ex := false
var fs = bson.M{}
for _, key := range fields {
_, _, columnName := GetFieldByJson(modelType, key)
if len(columnName) >= 0 {
fs[columnName] = 1
ex = true
}
}
if ex == false {
return nil
}
return fs
}
//For Search and Patch
func GetBsonName(modelType reflect.Type, fieldName string) string {
field, found := modelType.FieldByName(fieldName)
Expand Down

0 comments on commit fc58ded

Please sign in to comment.