Symfony2 で MongoDB をセットアップする際に問題があります。
仕様:
"Symfony": "2.6.*"
"doctrine/mongodb-odm": "1.0.*@dev",
"doctrine/mongodb-odm-bundle": "3.0.*@dev"
MongoDB の 2 つの異なるバンドル nxtlog と nxtsurvey で使用される 2 つのデータベースがあります。私が抱えていた最初の問題は、オプションに追加したデータベース名が考慮されていなかったため、データベースの「デフォルト」が使用され、もちろん存在しませんでした。また、両方の接続が非コア バンドルで使用されるため、default_connection と default_manager、さらには default_database も追加したくありません。
==== 試行 #1 ====
これが私が持っていた元の設定です:
doctrine_mongodb:
connections:
nxtlog:
server: "%nxtlog_database_server%"
options:
username: "%nxtlog_database_username%"
password: "%nxtlog_database_password%"
db: "%nxtlog_database_name%"
nxtsurvey:
server: "%nxtsurvey_database_server%"
options:
username: "%nxtsurvey_database_username%"
password: "%nxtsurvey_database_password%"
db: "%nxtsurvey_database_name%"
document_managers:
nxtlog:
mappings:
NxtLogBundle: ~
nxtsurvey:
mappings:
NxtVibeSurveyBundle: ~
機能させるために、各ドキュメント注釈にデータベースの名前を追加しました。
/**
* @MongoDB\Document(db="nxtlog")
*/
class ErrorLogs
これは一時的な解決策ですが、私の計画は他のプロジェクトでバンドルを再利用することであるため、すべてのドキュメントを調べてデータベースの名前を設定する必要はありません。
==== 試行 #2 ====
私の2番目の試みは、ドキュメントに厳密に従うことでした。そのため、次のことを試しました。
doctrine_mongodb:
connections:
nxtlog_conn:
server: "%nxtlog_database_server%"
options:
username: "%nxtlog_database_username%"
password: "%nxtlog_database_password%"
connect: true
db: "%nxtlog_database_name%"
nxtsurvey_conn:
server: "%nxtsurvey_database_server%"
options:
username: "%nxtsurvey_database_username%"
password: "%nxtsurvey_database_password%"
connect: true
db: "%nxtsurvey_database_name%"
document_managers:
nxtlog_dm:
connection: nxtlog_conn
mappings:
NxtLogBundle: ~
nxtsurvey_dm:
connection: nxtsurvey_conn
mappings:
NxtVibeSurveyBundle: ~
次のエラーが表示されます。
ServiceNotFoundException in CheckExceptionOnInvalidReferenceBehaviorPass.php line 58:
The service "doctrine_mongodb.odm.nxtlog_conn_connection" has a dependency on a non-existent service "doctrine_mongodb.odm.nxtlog_conn_configuration".
そのため、接続とデータマネージャーに異なる名前を付けることはできないことがわかりました。私はそれを信じていなかったので、私はそれをグーグルで検索しました.誰かが同様の問題を抱えていました.答えはdoctrine_mongodbの下に以下を追加することでした:
default_commit_options: ~
しかし、この解決策は私にはうまくいきませんでした。さらにグーグルで調べたところ、バンドル (またはその一部) を作成した jmikola が間違いを犯したことがわかりました。彼はそれを修正したと言い、default_commit_options は必要な構成オプション。(参照https://github.com/doctrine/DoctrineMongoDBBundle/issues/222 )
この時点で、解決に時間がかかりすぎるため、助けが必要です。
ありがとう