Set
Overview
Set returns bson.M for $set updates.
Part of the mongo package — Node.js analog: mongoose.
Signature
go
func Set(fields bson.M) bson.MCompare: 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"
update := mongo.Set("name", "Ada")Example
go
import "github.com/sahilkhaire/gox/mongo"
update := mongo.Set("name", "Ada")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))