Client.Connect
Overview
Connect dials uri.
If you are coming from Node.js, the closest pattern is mongoose.connect(uri).
Method on Client — call it on a value of that type after constructing or receiving one from a constructor.
Signature
go
func Connect(ctx context.Context, uri string) (*Client, error)Compare: Node.js · Standard Go · gox
js
await mongoose.connect(uri);go
client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri))go
import "github.com/sahilkhaire/gox/mongo"
client, err := mongo.Connect(ctx, uri)Example
go
import "github.com/sahilkhaire/gox/mongo"
client, err := mongo.Connect(ctx, uri)Tips
Pass context.Context as the first argument so cancellation and deadlines propagate correctly.
Standard library alternative
Use the standard library directly:
go
client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri))