How to configure two mongo databases in yii2?
If configured like this, an error will be reported in the model
But now the project needs to connect to two databases. How should it be configured? ? ?
The default project uses:Yii::$app->getDb($dbId);
對于mongodb
來說,他默認的第一個id應該是:mongodb;
但是你是設置成了:"mongo_dsp"和"mongo_dmp"所以會出現(xiàn)這個問題,想要實現(xiàn)就可以在Model構(gòu)造函數(shù)里面使用:Yii::$app->getDb("mongo_dsp");
to achieve the effect!