package mongo import ( "api-poliklinik/pkg/models/mongo/person" "context" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo/options" "log" "time" ) func (s *DatabaseService) GetAllPerson(limit int64, skip int64) ([]*person.Person, error) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() findOptions := options.Find() findOptions.SetLimit(limit) findOptions.SetSkip(skip) dataUser, err := s.DBMongo.Collection("person").Find(ctx, bson.D{}, findOptions) if err != nil { log.Println(err) } var users []*person.Person err = dataUser.All(ctx, &users) if err != nil { log.Println(err) return nil, err } return users, nil } func (s *DatabaseService) InsertPerson(req *person.Person) error { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() _, err := s.DBMongo.Collection("person").InsertOne(ctx, req) if err != nil { log.Println(err) return err } return nil }