Client
Overview
Client wraps mongo.Client.
Part of the mongo package — Node.js analog: mongoose.
Client is a type exported by gox. Methods on this type are documented separately.
Signature
go
type Client struct {
MC *mongo.Client
}Compare: Node.js · Standard Go · gox
js
// Typical mongoose pattern in Node.jsgo
client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri))go
import "github.com/sahilkhaire/gox/mongo"
client, err := mongo.Connect(ctx, "mongodb://localhost:27017")
if err != nil {
return err
}Example
go
import "github.com/sahilkhaire/gox/mongo"
client, err := mongo.Connect(ctx, "mongodb://localhost:27017")
if err != nil {
return err
}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))