简体   繁体   中英

Doctrine ODM Connection URI on ZF2

I'm using Zend Module DoctrineMongoODMModule and I would like to connect to MongoDB with Connection String

With array settings it working fine :

'server'    => 'localhost',
'port'      => '10152',
'user'      => 'test',
'password'  => 'test',
'dbname'    => 'base',
'options'   => array()

But when i want connect with URI like this :

'connectionString' => 'mongodb://test:test@server1:10152,server2:10152/base'

It doesnt work. I got this error :

The option "connectionString" does not have a matching setConnectionString setter method which must be defined

The reason that i want Uri connection is that I using Replica database and would like to connect both server.

The options usually start with snake_case and are converted into setters/getters. For the connection, the Connection options class is used . This options class is used by the connection factory .

First, you could try to set the connetion string with connection_string . I haven't tested it, but it should work according to the standards of the Options classes.

Next, you could set the server part with server1:10152,server2 . If you check the factory, all parts are just concatenated. It will result in a same version of the connection string build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM