loopbackio / loopbackio/loopback-next

Update the datasource/database read preference at the run time.

オープン
#9,388 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature
主要言語
TypeScript
スター
5.1k
フォーク
1.1k
平均マージ
2日 21時間
マージ済み PR(30日)
27

説明

### Describe the bug

For architectural reasons, I need to update the readPreference for a given method, on a given repository at the fly.
Please note, this change should be done at real time, and impact only this function invocation. However, the readPreferrence at the application level/datasource level should remain intact to "primaryPreferred".

For example,

```Javascript
this.userRepo.find(filter, { readPreference: "secondary" }); // request is still going to primary MongoDB server!
this.userRepo.findById(filter, { readPreference: "primary" });
```

I've tried this, but upon checking mongodb logs, this does not seem to work. All the request are going to primary server.

MongoDB version: v4.2

### Logs

```shell
NA
```

### Additional information

NA

### Reproduction

https://github.com/shivambmgupta/loopback-next/tree/bug/read-preference-update

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされた再現ブランチから始め、MongoDB 4.2 に対して、呼び出しごとの readPreference オプションを使用する find と findById による repository 呼び出しを追跡します。メソッドレベルの preference がその呼び出しだけを変更し、アプリケーションと datasource の設定は primaryPreferred のままであることを確認します。結果として選択されたサーバーを MongoDB のログで確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
mongodb, typescript
領域
backend, database
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。