Documentation ¶
Index ¶
- type MongoService
- type MyCollection
- func (m *MyCollection[T]) DeleteMany(filter bson.M, opts ...*options.DeleteOptions) error
- func (m *MyCollection[T]) DeleteOne(filter bson.M, opts ...*options.DeleteOptions) error
- func (m *MyCollection[T]) Find(filter bson.D, opts ...*options.FindOptions) (result []T, err error)
- func (m *MyCollection[T]) FindOneByIdString(id string) (result T, err error)
- func (m *MyCollection[T]) FindOneByObjectId(id primitive.ObjectID) (result T, err error)
- func (m *MyCollection[T]) InsertMany(document []T) error
- func (m *MyCollection[T]) InsertOne(document T) error
- func (m *MyCollection[T]) UpdateMany(filter bson.M, update bson.M, opts ...*options.UpdateOptions) error
- func (m *MyCollection[T]) UpdateOne(filter bson.M, update bson.M, opts ...*options.UpdateOptions) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MongoService ¶
type MongoService struct { Address string Conn *mongo.Client // contains filtered or unexported fields }
func Init ¶
func Init(address string) (*MongoService, error)
func (*MongoService) Close ¶
func (m *MongoService) Close() error
func (*MongoService) GetCollection ¶
func (m *MongoService) GetCollection(databaseName string, collectionName string) (interface{}, error)
MUST handle error!
Convert return interface into specific model ("models.Test" for example):
collectionInterface, err := mongoService.GetCollection(DatabaseName, models.TestCollectionName) if err != nil { t.Errorf("%v", err) return } collection := collectionInterface.(*mongo.MyCollection[models.Test])
type MyCollection ¶
type MyCollection[T any] struct { // contains filtered or unexported fields }
func (*MyCollection[T]) DeleteMany ¶
func (m *MyCollection[T]) DeleteMany(filter bson.M, opts ...*options.DeleteOptions) error
func (*MyCollection[T]) DeleteOne ¶
func (m *MyCollection[T]) DeleteOne(filter bson.M, opts ...*options.DeleteOptions) error
func (*MyCollection[T]) Find ¶
func (m *MyCollection[T]) Find(filter bson.D, opts ...*options.FindOptions) (result []T, err error)
MUST handle error!
func (*MyCollection[T]) FindOneByIdString ¶
func (m *MyCollection[T]) FindOneByIdString(id string) (result T, err error)
MUST handle error!
func (*MyCollection[T]) FindOneByObjectId ¶
func (m *MyCollection[T]) FindOneByObjectId(id primitive.ObjectID) (result T, err error)
MUST handle error!
func (*MyCollection[T]) InsertMany ¶
func (m *MyCollection[T]) InsertMany(document []T) error
MUST handle error!
func (*MyCollection[T]) InsertOne ¶
func (m *MyCollection[T]) InsertOne(document T) error
MUST handle error!
func (*MyCollection[T]) UpdateMany ¶
func (m *MyCollection[T]) UpdateMany(filter bson.M, update bson.M, opts ...*options.UpdateOptions) error
MUST handle error!
func (*MyCollection[T]) UpdateOne ¶
func (m *MyCollection[T]) UpdateOne(filter bson.M, update bson.M, opts ...*options.UpdateOptions) error
MUST handle error!
Click to show internal directories.
Click to hide internal directories.