func (r *EvaluationRepository) FindAllByReqHash(ctx context.Context, reqHash string) (flaggio.EvaluationList, error) {
	span, ctx := opentracing.StartSpanFromContext(ctx, "MongoEvaluationRepository.FindAllByReqHash")
	defer span.Finish()
	filter := bson.M{"requestHash": reqHash}
	cursor, err := r.col.Find(ctx, filter, &options.FindOptions{
		Sort: bson.M{"flagKey": 1},
	})
	if err != nil {
		return nil, err
	}
	var evals flaggio.EvaluationList
	for cursor.Next(ctx) {
		var e evaluationModel
		if err := cursor.Decode(&e); err != nil {
			return nil, err
		}
		evals = append(evals, e.asEvaluation())
	}
	if err := cursor.Err(); err != nil {
		return nil, err
	}
	return evals, nil
}
FindAllByReqHash returns all previous flag evaluations for a given request hash.
package mongodb
import (
	"context"
	"regexp"
	"time"
	"github.com/opentracing/opentracing-go"
	"github.com/victorkt/flaggio/internal/errors"
	"github.com/victorkt/flaggio/internal/flaggio"
	"github.com/victorkt/flaggio/internal/repository"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
)
var _ repository.Evaluation = (*EvaluationRepository)(nil)
type EvaluationRepository struct {
	db  *mongo.Database
	col *mongo.Collection
}
func (r *EvaluationRepository) FindAllByUserID(ctx context.Context, userID string, search *string, offset, limit *int64) (*flaggio.EvaluationResults, error) {
	span, ctx := opentracing.StartSpanFromContext(ctx, "MongoEvaluationRepository.FindAllByUserID")
	defer span.Finish()
	filter := bson.M{"userId": userID}
	if search != nil {
		filter["flagKey"] = primitive.Regex{Pattern: regexp.QuoteMeta(*search), Options: "i"}
	}
	cursor, err := r.col.Find(ctx, filter, &options.FindOptions{
		Skip:      offset,
		Limit:     limit,
		Sort:      bson.M{"flagKey": 1},
		Collation: &options.Collation{Locale: "en"},
	})
	if err != nil {
		return nil, err
	}
	var evals flaggio.EvaluationList
	for cursor.Next(ctx) {
		var e evaluationModel
		if err := cursor.Decode(&e); err != nil {
			return nil, err
		}
		evals = append(evals, e.asEvaluation())
	}
	if err := cursor.Err(); err != nil {
		return nil, err
	}
	total, err := r.col.CountDocuments(ctx, filter)
	if err != nil {
		return nil, err
	}
	return &flaggio.EvaluationResults{
		Evaluations: evals,
		Total:       int(total),
	}, nil
}