Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2306

Adding indexes to fields using StructTags

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Won't Do
    • Icon: Unknown 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.

      Attachments

        Activity

          People

            benji.rewis@mongodb.com Benji Rewis (Inactive)
            agarwal.lucky.shaurya11@gmail.com Shaurya Agarwal
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: