Files
mongo_eample/delete.go
2024-12-12 15:55:37 +03:00

25 lines
492 B
Go

package main
import (
"context"
"fmt"
"log"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
func deleteAllRows(ctx context.Context, coll *mongo.Collection) {
ctx, span := FollowSpan(ctx, "deleteAllRows")
defer span.End()
result, err := coll.DeleteMany(ctx, bson.D{})
if err != nil {
log.Fatal(result)
}
fmt.Println("Remove all documents...")
fmt.Printf("%d documents removed\n", result.DeletedCount)
fmt.Println("=============================")
}