Details
-
Improvement
-
Resolution: Won't Do
-
Unknown
-
None
-
None
-
None
-
None
Description
Defining indexes or unique fields in MongoDB in Golang requires one to create it manually for each field. It takes the index definition away from the main model definition.
I would like to propose a method to create indexes for each field using the StructTags
type User struct {
|
Id primitive.ObjectID
|
Email string `mongo:"unique"`
|
}
|
I created something similar for this here: Migrate() function
The above-mentioned method is definitely not perfect, since I created it for one-time use.
The working on the method can be tested here: ShauryaAg/ProductAPI
I would love to work on this.