Support for DB_URI in mongodb database driver
- Ngôn ngữ chính
- Go
- Star
- 1.2k
- Fork
- 69
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
Peekaping currently builds the mongodb URI from user-supplied variables (see [related code](https://github.com/0xfurai/peekaping/blob/d22eba52a5250aaa914a8df87bddd7478c6af449/apps/server/internal/infra/mongo.go#L48)). The main issue is that mongodb supports a lot of connection customization in URI form, as you can see in the [mongodb documentation](https://www.mongodb.com/docs/manual/reference/connection-string-self-managed-examples/#std-label-connections-connection-examples-self-managed)
In my specific case, I host a managed, shared mongodb cluster in replica-set style, and service discovery is via consul SRV. If I can supply my own URI, then I could simply use "mongodb+srv://" and the mongodb driver will automatically resolve the endpoints for peekaping
I think the user should be able to provide its own URI via an environment variable, and it should take precedence over the "unmounted" database variables. The [mongo-go-driver](https://github.com/mongodb/mongo-go-driver) automatically resolves the URI by itself but I'm not sure about [bun](https://github.com/uptrace/bun) for other database drivers
Also, I don't think hardcoding `authSource=admin` is a good practice
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
The code to modify is in apps/server/internal/infra/mongo.go around line 48. First, read the existing URI-building logic and the mongo-go-driver documentation. Add support for a DB_URI environment variable that overrides the constructed URI. Ensure the change works with bun for other databases. Test by setting the environment variable and verifying the connection works with a MongoDB SRV URI.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- go, mongodb
- Lĩnh vực
- backend, databases
- Loại issue
- Tính năng
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 65/100