Skip to content

tuxnotes/recipes-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golang code for insert users to mongodb

func main() {
   users := map[string]string{
       "admin":      "fCRmh4Q2J7Rseqkz",
       "packt":      "RE4zfHB35VPtTkbT",
       "mlabouardy": "L3nSFRcZzNQ67bcc",
   }
   ctx := context.Background()
   client, err := mongo.Connect(ctx,
       options.Client().ApplyURI(os.Getenv("MONGO_URI")))
   if err = client.Ping(context.TODO(),
          readpref.Primary()); err != nil {
       log.Fatal(err)
   }
   collection := client.Database(os.Getenv(
       "MONGO_DATABASE")).Collection("users")
   h := sha256.New()
   for username, password := range users {
       collection.InsertOne(ctx, bson.M{
           "username": username,
           "password": string(h.Sum([]byte(password))),
       })
   }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages