go get github.com/AlexGalhardo/vukem/drivers/mongom, err := mongo.Open(ctx, os.Getenv("MONGO_URL")) // mongodb://localhost:27017/app (database from the path)
app.AddHealthCheck("mongo", m.Ping) // reported by /up?checks=1
users := mongo.Collection[models.User](m, "users")
u, err := users.FindOne(ctx, bson.D{{Key: "email", Value: email}}) // mongo.ErrNotFound when missing
for u, err := range users.Find(ctx, bson.D{{Key: "active", Value: true}}, options.Find().SetLimit(50)) {
// break to stop early; the cursor is closed
}
id, err := users.Insert(ctx, u)
matched, modified, err := users.UpdateOne(ctx, filter, bson.D{{Key: "$set", Value: bson.D{{Key: "name", Value: n}}}})
totals, err := mongo.Aggregate[Total](ctx, users, pipeline)Also All, Count, InsertMany, UpdateMany, ReplaceOne, DeleteOne, DeleteMany, and Raw() on the client and on collections for indexes, transactions and change streams. The database name can also be passed as mongo.Open(ctx, uri, "app").
MongoDB has its own API on purpose: the SQL query builder and migrations do not apply to it.