Add method to retrieve collection

This commit is contained in:
Anton Zadvorny 2024-04-08 05:14:12 +03:00
parent 947d01e7df
commit a5822f1508

View File

@ -12,6 +12,8 @@ import (
)
type RepositoryInterface[T Document] interface {
Collection() *mongo.Collection
Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) ([]T, error)
FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (T, error)
FindByID(ctx context.Context, id string, opts ...*options.FindOneOptions) (T, error)
@ -36,6 +38,10 @@ func NewRepository[T Document](collection *mongo.Collection, indexes []mongo.Ind
return &Repository[T]{collection: collection, indexes: withTimestampIndexes(indexes)}
}
func (s *Repository[T]) Collection() *mongo.Collection {
return s.collection
}
func (s *Repository[T]) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) ([]T, error) {
cursor, err := s.collection.Find(ctx, filter, opts...)
if err != nil {