// UpdateUser allows to update one or more user characteristics
UpdateUser allows to update one or more user characteristics
// UpdateUser allows to update one or more user characteristics
func (db *Mngo) UpdateUser(userID string, newUser *models.User) error {
	c := db.database.Collection(models.UsersCollection)
	result, err := c.UpdateOne(context.TODO(), bson.M{"_id": userID}, bson.M{"$set": newUser}, options.Update().SetUpsert(true))
	if err != nil {
		log.Fatal(err)
		return helpers.NewError(http.StatusInternalServerError, "user_update_failed", "Failed to update the user", err)
	}
	if result.MatchedCount != 0 {
		fmt.Println("matched and replaced an existing document")
		return nil
	}
	if result.UpsertedCount != 0 {
		fmt.Printf("UpdateUser: inserted a new document with ID %v\n", result.UpsertedID)
		return nil
	}
	return nil
}
func ( db * Mngo ) UpdateUser ( userID string , newUser * models . User ) error { c := db . database . Collection ( models . UsersCollection ) result , err := c . UpdateOne ( context . TODO ( ) , bson . M { " " : userID } , bson . M { " " : newUser } , options . Update ( ) . SetUpsert ( true ) ) if err != nil { log . Fatal ( err ) return helpers . NewError ( http . StatusInternalServerError , " " , " " , err ) } if result . MatchedCount != 0 { fmt . Println ( " " ) return nil } if result . UpsertedCount != 0 { fmt . Printf ( " \n " , result . UpsertedID ) return nil } return nil }
UpdateUser allows to update one or more user characteristics
UpdateUser allows to update one or more user characteristics