github.com/RevenueMonster/sqlike@v1.0.6/examples/mongo.go (about)

     1  package examples
     2  
     3  import (
     4  	"context"
     5  
     6  	"go.mongodb.org/mongo-driver/mongo"
     7  	"go.mongodb.org/mongo-driver/mongo/options"
     8  )
     9  
    10  func connectMongoDB(ctx context.Context) *mongo.Database {
    11  	client, err := mongo.NewClient(
    12  		options.Client().
    13  			ApplyURI("mongodb://localhost:27017").
    14  			SetAuth(options.Credential{
    15  				Username: "root",
    16  				Password: "abcd1234",
    17  			}))
    18  	if err != nil {
    19  		panic(err)
    20  	}
    21  	if err := client.Connect(ctx); err != nil {
    22  		panic(err)
    23  	}
    24  	return client.Database("sqlike")
    25  }