From a5822f1508109f6fa83d5c52a8be0b20a1d004a6 Mon Sep 17 00:00:00 2001 From: Anton Zadvorny Date: Mon, 8 Apr 2024 05:14:12 +0300 Subject: [PATCH] Add method to retrieve collection --- repository.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/repository.go b/repository.go index b043772..ff42588 100644 --- a/repository.go +++ b/repository.go @@ -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 {