Guest User

Untitled

a guest
Jan 20th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. package db
  2.  
  3. import (
  4. "context"
  5. "github.com/mongodb/mongo-go-driver/mongo"
  6. )
  7.  
  8. func GetDBCollection() (*mongo.Collection, error) {
  9. client, err := mongo.Connect(context.TODO(), "mongodb://localhost:27017")
  10. if err != nil {
  11. return nil, err
  12. }
  13. // Check the connection
  14. err = client.Ping(context.TODO(), nil)
  15. if err != nil {
  16. return nil, err
  17. }
  18. collection := client.Database("GoLogin").Collection("users")
  19. return collection, nil
  20. }
Add Comment
Please, Sign In to add comment