search

Home  >  Q&A  >  body text

mongodb - yii2 how to configure two mongo databases

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? ? ?

过去多啦不再A梦过去多啦不再A梦2853 days ago841

reply all(1)I'll reply

  • 为情所困

    为情所困2017-05-02 09:26:09

    The default project uses:Yii::$app->getDb($dbId);
    对于mongodb来说,他默认的第一个id应该是:mongodb;
    但是你是设置成了:"mongo_dsp"和"mongo_dmp"所以会出现这个问题,想要实现就可以在Model构造函数里面使用:
    Yii::$app->getDb("mongo_dsp");to achieve the effect!

    reply
    0
  • Cancelreply