Add method to retrieve collection
This commit is contained in:
		
							parent
							
								
									947d01e7df
								
							
						
					
					
						commit
						a5822f1508
					
				| @ -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 { | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user